首页  >  问答  >  正文

致命错误:找不到类'NumberFormatter'

<p>我已经使用这段完全相同的代码很久了,从来没有出过任何问题。突然间它停止工作了。</p> <p>我在互联网上阅读了关于这个问题的资料,显然你需要安装<code>PHP 5.3或更高版本</code>,以及安装<code>PHP intl</code>插件。我两者都有,但是每当我使用下面的函数时,我仍然收到一个<code>致命错误:找不到类'NumberFormatter'</code>的错误:</p> <pre class="brush:php;toolbar:false;">function format_item($value) { $format = new NumberFormatter('en_US', NumberFormatter::CURRENCY); return $format->formatCurrency($value, 'AUD'); }</pre> <p>此外,这是我<code>php.ini</code>文件的一部分,显示我已经安装了<code>PHP intl</code>插件:</p> <pre class="brush:php;toolbar:false;">[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</pre> <p>我还在我的<code>php.ini</code>中添加了<code>extension=php_intl.dll</code>,并且它也在我的目录中。</p> <p>为什么我会收到这个错误?</p>
P粉817354783P粉817354783399 天前491

全部回复(2)我来回复

  • P粉409742142

    P粉4097421422023-08-17 14:47:15

    你所需要的是:

    apt-get install php7.0-intl

    无需更改php.ini或进行其他操作。(在Ubuntu 16.04上测试过PHP 7)。

    这里最受欢迎的答案是让你取消注释一个.dll文件,除非你在Windows服务器上,否则这永远不会解决任何问题!

    回复
    0
  • P粉237029457

    P粉2370294572023-08-17 12:07:58

    这似乎是一个非常奇怪的问题,我通过以下方式解决了它:

    我通过这个教程升级了我的Wamp中的PHP。我还更新了php.ini中的时区设置。当我升级后,它没有起作用,所以我恢复回了之前的PHP版本,然后问题就解决了。

    我完全不知道这样做为什么能解决问题,但对我来说有效。

    回复
    0
  • 取消回复