目前我所知道的唯一全局PHP命令是:
<?=$text_items?>
这唾沫:
1 item(s) - £318.75
我想得到318.75
的值,所以目前我正在尝试更换,但工作并不顺利:
$short = $text_items;
$short = str_replace("£", "", $short);
$short = str_replace("£", "", $short);
$short = str_replace("-", "", $short);
$short = str_replace("–", "", $short);
$short = str_replace(" ", "", $short);
$short = str_replace("-", "", $short);
$short = str_replace("ITEMS", "", $short);
$short = str_replace("(", "", $short);
$short = str_replace(")", "", $short);
$short = str_replace("item(s)", "", $short);
$short = str_replace("ITEM", "", $short);
$total = @floatval(end(explode('£', html_entity_decode($text_items))));
html_entity_decode
将£
更改为£
end(explode('£'
在"£
"字符后为您提供字符串- 最后CCD_ 7将字符串赋值为float
- @绕过了CCD_ 9函数中传递常数时出现的CCD_
工作示例
第二个解决方案是Regexp:
preg_match_all('!'d+(?:'.'d+)?!', $text_items, $result);
echo $result[1];
工作示例