久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

從 PHP 中的字符串中提取浮點(diǎn)數(shù)

Extract floating point numbers from a string in PHP(從 PHP 中的字符串中提取浮點(diǎn)數(shù))
本文介紹了從 PHP 中的字符串中提取浮點(diǎn)數(shù)的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號(hào)..

我想將字符串轉(zhuǎn)換為浮點(diǎn)數(shù).例如

I would like to convert a string into floating numbers. For example

152.15 x 12.34 x 11mm

進(jìn)入

152.15, 12.34 and 11

并存儲(chǔ)在一個(gè)數(shù)組中,使得 $dim[0]=152.15, $dim[1]=12.34, $dim[2]=11.

and store in an array such that $dim[0]=152.15, $dim[1]=12.34, $dim[2]=11.

我還需要處理諸如

152.15x12.34x11 mm

152.15mmx12.34mm x 11mm

謝謝.

推薦答案

$str = '152.15 x 12.34 x 11mm';
preg_match_all('!d+(?:.d+)?!', $str, $matches);
$floats = array_map('floatval', $matches[0]);
print_r($floats);

(?:...) 正則表達(dá)式構(gòu)造就是所謂的 非捕獲組.這意味著該塊沒有在 $mathces 數(shù)組的一部分中單獨(dú)返回.這不是絕對(duì)必要的在這種情況下,但這是一個(gè)有用的結(jié)構(gòu).

The (?:...) regular expression construction is what's called a non-capturing group. What that means is that chunk isn't separately returned in part of the $mathces array. This isn't strictly necessary in this case but is a useful construction to know.

注意:調(diào)用floatval()在元素上也不是絕對(duì)必要的,因?yàn)槿绻鷩L試在算術(shù)運(yùn)算或類似操作中使用它們,PHP 通常會(huì)正確處理類型.不過,這并沒有什么壞處,尤其是只作為一個(gè)班輪.

Note: calling floatval() on the elements isn't strictly necessary either as PHP will generally juggle the types correctly if you try and use them in an arithmetic operation or similar. It doesn't hurt though, particularly for only being a one liner.

這篇關(guān)于從 PHP 中的字符串中提取浮點(diǎn)數(shù)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產(chǎn)品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產(chǎn)品的總訂單數(shù))
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗(yàn)證問題中添加自定義注冊(cè)字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡(jiǎn)單產(chǎn)品中添加一個(gè)將更改價(jià)格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產(chǎn)品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結(jié)帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 玖玖精品| 99reav| 成人精品视频免费 | 在线国产一区 | 欧美一区二区视频 | 中文字幕亚洲精品 | 欧美一级免费看 | 能看的av| 午夜理伦三级理论三级在线观看 | 国产精品视频在线观看 | 日本a在线| 中文字幕电影在线观看 | 精品av| 国产一级片| 久草网址 | 国产人成精品一区二区三 | 99国产精品视频免费观看一公开 | 国产精品久久久久久久久久久久久久 | 亚洲国产精品网站 | 精品欧美一区二区在线观看欧美熟 | 久久亚洲免费 | 少妇淫片aaaaa毛片叫床爽 | 亚洲国产精品久久久久秋霞不卡 | 一区二区三区四区视频 | 久久久久中文字幕 | 国产高清视频在线观看 | 欧美精品乱码久久久久久按摩 | 欧美一区二区三区免费电影 | 亚洲精品播放 | 精品一区二区三区在线观看 | 国产成人久久精品一区二区三区 | 亚洲视频在线一区 | 美女爽到呻吟久久久久 | 涩涩视频大全 | 日韩精品一区二区三区四区 | 亚洲成人毛片 | 欧美激情在线精品一区二区三区 | 91在线精品一区二区 | 一区二区日韩 | 手机看黄av免费网址 | 久久成人国产精品 |