php 致命错误:找不到“NumberFormatter”类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30554177/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fatal error: Class 'NumberFormatter' not found
提问by cannatown
I've been using this exact same code for ages, and I have never had a single problem. Now all of a sudden it has stopped working.
我已经使用这个完全相同的代码多年了,我从来没有遇到过任何问题。现在突然它停止工作了。
I have read across the internet about this problem, and apparently you need PHP 5.3 or higher
installed, and the PHP intl
plugin installed. I have both of these, yet I am still receiving a Fatal error: Class 'NumberFormatter' not found
error whenever I use the following function:
我已经在互联网上阅读了有关此问题的信息,显然您需要PHP 5.3 or higher
安装并PHP intl
安装插件。我有这两个,但Fatal error: Class 'NumberFormatter' not found
每当我使用以下功能时,我仍然收到错误:
function format_item($value)
{
$format = new \NumberFormatter('en_US', \NumberFormatter::CURRENCY);
return $format->formatCurrency($value, 'AUD');
}
Also, here is a snippit from my php.ini
file showing that I have the PHP intl
plugin installed:
另外,这是我的php.ini
文件中的一个片段,显示我安装了PHP intl
插件:
[intl]
intl.default_locale = fr_FR
; This directive allows you to produce PHP errors when some error
; happens within intl functions. The value is the level of the error produced.
; Default is 0, which does not produce any errors.
intl.error_level = E_WARNING
I also have the extension=php_intl.dll
in my php.ini
, and it is also in my directory.
我也有extension=php_intl.dll
我的php.ini
,这也是我的目录。
Why am I getting this error?
为什么我收到这个错误?
采纳答案by cannatown
This seems to be some really weird problem, and I somehow fixed it by doing the following:
这似乎是一些非常奇怪的问题,我通过执行以下操作以某种方式修复了它:
I upgraded my PHP in Wamp through thistutorial. I also updated my timezone in php.ini
When I upgraded it didn't work, so I reverted back to my previous version of PHP, and voilà - it worked.
我通过本教程在 Wamp 中升级了我的 PHP 。我还更新了我的时区,php.ini
当我升级时它不起作用,所以我恢复到我以前的 PHP 版本,瞧——它起作用了。
I have absolutely no idea how this solved the problem, however it worked for me.
我完全不知道这是如何解决问题的,但它对我有用。
回答by Chandz
YOu just need to enable this extension in php.ini by uncommenting this line: extension=ext/php_intl.dll
你只需要通过取消注释这一行来在 php.ini 中启用这个扩展:extension=ext/php_intl.dll
For more details visit, Enable intl extension
有关更多详细信息,请访问启用国际扩展
回答by Nick
All you need is:
所有你需要的是:
apt-get install php7.0-intl
No need to change php.ini or do anything else. (Tested on PHP 7 on Ubuntu 16.04).
无需更改 php.ini 或执行任何其他操作。(在 Ubuntu 16.04 上的 PHP 7 上测试)。
The most up-voted answer here has you uncommenting a .dll which will never solve anything unless you are on a Windows server!
此处投票最多的答案是取消对 .dll 的注释,除非您在 Windows 服务器上,否则它将永远无法解决任何问题!
回答by keya
I am using PHP 5.5 version and got the same error in Ubuntu Machine. I have installed php5-Intl package and restarted my apache server.This resolved the issue.
我正在使用 PHP 5.5 版本并在 Ubuntu Machine 中遇到相同的错误。我已经安装了 php5-Intl 包并重新启动了我的 apache 服务器。这解决了问题。
For PHP5
对于 PHP5
sudo apt-get install php5-intl
For PHP7
对于 PHP7
sudo apt-get install php7.0-intl
For Mac OS X, use the following command for PHP5.6
对于 Mac OS X,PHP5.6 使用以下命令
brew install php56-intl
For different OS, checkout this page : http://php.net/manual/en/intl.installation.php
对于不同的操作系统,请查看此页面:http: //php.net/manual/en/intl.installation.php
To check successful installation, run the command php -m. This should show the intl package in the list.
要检查安装是否成功,请运行命令 php -m。这应该在列表中显示 intl 包。
If you are using XAMPP in Mac OS X, php-intl will sometimes create different problems. You can follow the debug steps mentioned here
如果您在 Mac OS X 中使用 XAMPP,php-intl 有时会产生不同的问题。您可以按照此处提到的调试步骤进行操作
If you are facing Unable to load dynamic library '/usr/lib/php/extensions/no-debug-non-zts-20121212/intl.so'error, follow the steps as mentioned here
如果您遇到无法加载动态库 '/usr/lib/php/extensions/no-debug-non-zts-20121212/intl.so'错误,请按照此处提到的步骤操作
回答by Wonko the Sane
This worked for me (Ubuntu 18.10, PHP 7.2.15)
这对我有用(Ubuntu 18.10,PHP 7.2.15)
sudo apt-get install php-intl
service apache2 restart
回答by Ben Shoval
If you are using Google App Engine, just add:
如果您使用的是 Google App Engine,只需添加:
extension = "intl.so"
to your application's php.ini file.
到您的应用程序的 php.ini 文件。
回答by mizan3008
I am running on ubuntu-16.04 and I am using php7, I had the same issue, It is because of the php_intlextension
我在 ubuntu-16.04 上运行,我使用的是 php7,我遇到了同样的问题,这是因为php_intl扩展
the way I fixed it-
我修复它的方式-
First check the extension is installed or not on your server, use below command to check it
php -m | grep intl
If there's no results, you must need to install it
If not installed, let's install it
sudo apt-get update sudo apt-get install php-intl
Finally you need to restart your web server after you install
首先检查您的服务器上是否安装了扩展,使用以下命令进行检查
php -m | grep intl
如果没有结果,则必须安装它
如果没有安装,让我们安装它
sudo apt-get update sudo apt-get install php-intl
最后,您需要在安装后重新启动 Web 服务器
Class 'NumberFormatter' not found error in simple PHP program
在简单的 PHP 程序中找不到“NumberFormatter”类错误
回答by Vladimir Vukanac
outdated
过时的
On Max OS Xwith PHP installed with the Homebrew, we can:
在安装了Homebrew 的PHP 的Max OS X上,我们可以:
We can check is module intl
installed:
我们可以检查是否intl
安装了模块:
$ php -m
We can check module info:
我们可以检查模块信息:
$ brew info php72-intl
And installit with:
并安装它:
$ brew install php72-intl
回答by quent
Add your PHP directory in the Path environment variable. (C:\Program Files\wamp\bin\php\phpX.XXX.XXX for wamp)
在 Path 环境变量中添加您的 PHP 目录。(C:\Program Files\wamp\bin\php\phpX.XXX.XXX 为 wamp)
It has worked for me!
它对我有用!
回答by Delino
i could just do the following and it will work perfect.
我可以做以下事情,它会完美地工作。
$numbers = 123456789;
$toThousands = number_format($numbers);
results will be: 123,456,789, the func "number_format" is already build in function.
结果将是:123,456,789,函数“number_format”已经内置函数。
回答by saad
Change in php extensions did not work for me so I updated my php version from php 5.6.25 to 7.0.10 and it worked
更改 php 扩展名对我不起作用,所以我将我的 php 版本从 php 5.6.25 更新到 7.0.10 并且它起作用了