php - 在简单的 PHP 程序中找不到类 'NumberFormatter' 错误

标签 php numberformatter

我有一个简单的 PHP 程序,但我遇到了这个错误:

Class 'NumberFormatter' not found

我在 Stackoverflow 中研究过类似的问题,但老实说没有一个给出具体的解决方案。其他人建议升级 PHP 版本,其他人则取消注释 php.ini 文件中的特定行,但这些都不适合我。

下面是我的代码:我什至使用了 https://bugs.php.net 中建议的解决方案但它仍然不起作用。

<!DOCTYPE html>
<html>
<body>

<?php
function writeMsg(){

$f = new \NumberFormatter("en", \NumberFormatter::SPELLOUT);    

echo $f->format(1432);
}
writeMsg();
?>  

</body>
</html>

最佳答案

两件事

  1. 您需要 PHP 5.3 或更高版本。

  2. 您可能没有安装 php-intl 扩展。

要检查,请在您的终端中运行:

php -m | grep intl

如果没有结果,您需要安装它,具体取决于您的系统和 PHP 版本

例如,在 Mac 上,您可以通过运行以下命令为 PHP 5.6 安装它:

brew install php56-intl

确保在安装后重新启动 Web 服务器!

XAMPP 的编辑:

如果您正在运行 XAMPP,那么它可能已安装但未启用。

  1. 找到您的 php.ini 文件 -- path-to-your-xampp/php/php.ini -- 并在编辑器中打开它。

  2. 搜索 php_intl。如果您找到 ;extension=php_intl.dll,则只需删除该行前面的分号——这将取消注释。

  3. 重启 XAMPP!

关于php - 在简单的 PHP 程序中找不到类 'NumberFormatter' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33876590/

相关文章:

php - UTF-8贯穿始终

php - symfony 2.8 : id AND uid column in same table

php - Laravel API Controller 结构?

php - WordPress child 主题 : How do I add a custom style sheet from my parent theme to my child theme?

java - 十六进制 Jspinner 的一些提示?方法正确吗

php - 如何更改 NumberFormatter::parseCurrency() 接受空格和不间断空格的行为?

php - 在 PayPal 核心 sdk 中找不到类 "String"错误

ios - Swift iOS - 将货币格式的字符串转换为数字

Swift 3 类型转换或 NumberFormatter

PHP PECL 扩展 intl 给出瑞典序数的乱码结果