2012-05-23 15 views
10

爲什麼會發生此錯誤?在money_format函數中出現致命錯誤

代碼:

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

你有任何其他代碼?這應該工作;唯一的原因,我可以建議在這個交界處,你是在一個命名空間... –

+3

可能的重複[我們如何可以使用money_format()函數在windows平臺上的php.?](http://stackoverflow.com/questions/6369887/how-we-can-use-money-format-function-in-php-on-windows-platform) – deceze

+0

這是解決方案..它工作.http://www.php.net/manual/en /function.money-format.php#89060 – Parthi04

回答

15

manual

如果系統有strfmon 能力的功能money_format()僅限定。例如,Windows沒有,所以money_format()是 在Windows中未定義。

money_format()基本上是C庫函數strfmon()作爲手冊狀態的一個包裝。

如果您檢查評論,有an implementation by Rafael M. Salvioni。值得一試。你可以檢查它是否已經使用function_exists()定義。

this StackOverflow question的答案給出了更多(也可能更好)的備選方案(thx danielson317)。

+0

我只是添加功能,有一個由Rafael M. Salvioni到我的網站然後它的作品。 +1爲鏈接 – bungdito

+0

該功能對我無效。我得到嚴重性:警告 消息:implode():傳遞的參數無效 – CMCDragonkai

+1

intl模塊在http://stackoverflow.com/questions/6369887/how-we-can-use-money-format-function-in- php-on-windows-platform是一個更好的解決方案。 仍然+1是一個有效的答案。 – danielson317

1

也許這?

注:

money_format()如果系統有strfmon功能只被定義的功能。例如,Windows不會,所以money_format()在Windows中未定義。

http://php.net/money_format

+0

有沒有解決窗口的問題? – Parthi04

+1

http://stackoverflow.com/questions/6369887/how-we-can-use-money-format-function-in-php-on-windows-platform – deceze

4

對於那些money_format不起作用,你可以使用:

$price = number_format($price, 2); echo 「$」.$price; 
+0

謝謝。這幫助我在Windows! +1 upvoted – Tchaps