亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

strip_tags + html 實體只獲取數字

strip_tags + html 實體只獲取數字

PHP
慕村225694 2021-08-28 15:37:22
我想從這個字符串中刪除除金額以外的所有內容:<span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&#8362;</span>700.00</span>我試過:strip_tags( $total_price_paid ); - 不夠。strip_tags( html_entity_decode( $total_price_paid ) ); - 它將實體解碼為一個符號,之后我嘗試了 preg_replace 但它沒有用。preg_replace( '/[^0-9]/', '', $value ); - 沒有擺脫 html 實體這些都沒有獲得700.00格式化為浮點數的結果。有人可以幫忙嗎?
查看完整描述

3 回答

?
精慕HU

TA貢獻1845條經驗 獲得超8個贊

您還需要刪除用于定義實體的特殊文本片段,因此您至少需要另一遍:


$total_price_paid = strip_tags($total_price_paid);

$total_price_paid = preg_replace("/&#?[a-z0-9]{2,8};/i", "", $total_price_paid); 


查看完整回答
反對 回復 2021-08-28
?
猛跑小豬

TA貢獻1858條經驗 獲得超8個贊

如果你想使用 preg_match 那么你可以這樣使用:


$string = '<span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">&#8362;</span>700.00</span>';


preg_match('/\d+\.\d{1,2}/', $string, $matches);


echo $matches[0]; // 700.00


查看完整回答
反對 回復 2021-08-28
?
烙印99

TA貢獻1829條經驗 獲得超13個贊

$str = '<span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-currencySymbol">?</span>700.00</span>';


echo floatval(substr($str, stripos($str, "</span>")+7, strripos($str, "</span>")+7));



查看完整回答
反對 回復 2021-08-28
  • 3 回答
  • 0 關注
  • 154 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號