为什么会出现此错误?
代码:
setlocale(LC_MONETARY, "en_US");
$pricetotal = money_format("%10.2n", $pricetotal);
服务器详情。
Apache Version : 2.2.21
PHP Version : 5.3.8
我收到以下错误
Fatal error: Call to undefined function money_format()
答案 0 :(得分:15)
来自manual:
仅在系统具有
money_format()
时才定义函数strfmon
能力。例如,Windows没有,因此money_format()
是 在Windows中未定义。
money_format()
基本上是C库函数strfmon()
的包装器,如手册所述。
如果您查看评论,则会an implementation by Rafael M. Salvioni。值得一试。您可以使用function_exists()检查是否已经定义了它。
this StackOverflow question的答案提供了更多(可能更好)的替代方案(thx danielson317)。
答案 1 :(得分:4)
对于money_format不起作用的人,您可以使用:
$price = number_format($price, 2); echo “$”.$price;
答案 2 :(得分:1)
也许这个?
注意:
仅在系统具有
money_format()
功能时才定义函数strfmon
。例如,Windows没有,因此在Windows中未定义money_format()
。