如何在OpenCart的任何页面上显示小计? [英] How can I display the SubTotal on OpenCart on any page?

查看:68
本文介绍了如何在OpenCart的任何页面上显示小计?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Currently the only global PHP command I know is:

<?=$text_items?>

这吐口水:

1 item(s) - £318.75

我想获取318.75值,因此在我尝试进行替换时,它无法正常运行:

I want to get the 318.75 value so at the moment I am trying a replace but it is not working all smoothly:

$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('£'在'£'字符后给您字符串
  • 最终floatval正在评估要浮动的字符串.
  • @绕过了E_STRICT错误,该错误是由于在end()函数中传递常量所致.
    • html_entity_decode changes &pound; to £
    • end(explode('£' is giving you string after '£' character
    • finally floatval is valuating string to float.
    • @ is bypassing E_STRICT error which occurs to passing constant in end() function.
    • 工作示例

      第二个解决方案是Regexp:

      Second solution is Regexp:

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

      工作示例

      这篇关于如何在OpenCart的任何页面上显示小计?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆