首頁  >  問答  >  主體

致命錯誤:找不到類別'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 天前490

全部回覆(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
  • 取消回覆