Class 'NumberFormatter' not found error in simple PHP program

蓝咒 提交于 2019-11-30 05:48:32

问题


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

Class 'NumberFormatter' not found

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.

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:


Two things

  1. You need PHP 5.3 or above.

  2. You may not have the php-intl extension installed.

To check, run in your terminal:

php -m | grep intl

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

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

brew install php56-intl

Make sure you restart your web server after you install!

EDIT for XAMPP:

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

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

  2. 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.

  3. Restart XAMPP!




回答2:


As stated, you should have PHP 5 >= 5.3.0 version and if you already uncomment ;extension=php_intl.dll from php.ini file and still not working.. try to take a look at this answer. it really solve my problem.

intl extension php_intl.dll with wamp



来源:https://stackoverflow.com/questions/33876590/class-numberformatter-not-found-error-in-simple-php-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!