目前我所知道的唯一全局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);
答案 0 :(得分:2)
$total = @floatval(end(explode('£', html_entity_decode($text_items))));
html_entity_decode
将£
更改为£
end(explode('£'
在'£
'字符floatval
正在评估字符串浮动。E_STRICT
函数中传递常量时发生的end()
错误。第二个解决方案是Regexp:
preg_match_all('!\d+(?:\.\d+)?!', $text_items, $result);
echo $result[1];