在简单的PHP程序中找不到"NumberFormatter"类错误 [英] Class 'NumberFormatter' not found error in simple PHP program

查看:185
本文介绍了在简单的PHP程序中找不到"NumberFormatter"类错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a simple PHP program but I am encountering this error:

找不到"NumberFormatter"类

Class 'NumberFormatter' not found

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

I have researched similar issues in Stackoverflow but honestly none gave a concrete solution. Others suggest to upgrade the version of PHP, others un-comment a specific line in the php.ini file and none of those worked for me.

下面是我的代码:我什至使用了 https://bugs中的建议解决方案.php.net ,但仍然无法正常工作.

Below is my code: I even used the suggested solution from https://bugs.php.net but it still doesn't work.

<!DOCTYPE html>
<html>
<body>

<?php
function writeMsg(){

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

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

</body>
</html>

推荐答案

两件事

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

  1. You need PHP 5.3 or above.

您可能未安装php-intl扩展名.

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

To check, run in your terminal:

php -m | grep intl

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

If there's no results, you'll need to install it which varies depending on your system and PHP Version

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

On a Mac for example, you can install it for PHP 5.6 by running:

brew install php56-intl

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

Make sure you restart your web server after you install!

编辑XAMPP:

如果您正在运行XAMPP,则可能已安装但未启用.

If you're running XAMPP, then this is probably installed but not enabled.

  1. 找到您的php.ini文件-您的xampp路径/php/php.ini-并在编辑器中将其打开.

  1. Find your php.ini file -- path-to-your-xampp/php/php.ini -- and open it in an editor.

搜索php_intl.如果找到;extension=php_intl.dll,则只需从行的开头删除分号-即可取消注释.

Search for php_intl. If you find ;extension=php_intl.dll, then just remove the semi-colon from the front of the line -- this uncomments it.

重新启动XAMPP!

这篇关于在简单的PHP程序中找不到"NumberFormatter"类错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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