如何在任何页面上显示OpenCart上的SubTotal


How can I display the SubTotal on OpenCart on any page?

目前我所知道的唯一全局PHP命令是:

<?=$text_items?>

这唾沫:

1 item(s) - £318.75

我想得到318.75的值,所以目前我正在尝试更换,但工作并不顺利:

$short = $text_items;
$short = str_replace("£", "", $short);
$short = str_replace("&pound;", "", $short);
$short = str_replace("-", "", $short);
$short = str_replace("&ndash;", "", $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&pound;更改为£
  • end(explode('£'在"£"字符后为您提供字符串
  • 最后CCD_ 7将字符串赋值为float
  • @绕过了CCD_ 9函数中传递常数时出现的CCD_

工作示例


第二个解决方案是Regexp:

preg_match_all('!'d+(?:'.'d+)?!', $text_items, $result);
echo $result[1];

工作示例