Laravel 5.4 中未找到“NumberFormatter”类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44095680/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 16:00:50  来源:igfitidea点击:

Class 'NumberFormatter' not found in Laravel 5.4

phplaravellaravel-5.4numberformatter

提问by anonym

I'm trying to use PHP's intl extension to convert amount into words. For example,

我正在尝试使用 PHP 的 intl 扩展名将数量转换为单词。例如,

1450 -> One Thousand Four Hundred and Fifty

第1450章一千四百五十

I'm using Laravel 5.4 that runs on XAMPP 3.2.2 server with PHP 5.6.24.

我正在使用 Laravel 5.4,它在带有 PHP 5.6.24 的 XAMPP 3.2.2 服务器上运行。

As mentioned in similar questions, I've already enabled the intlPHP extension by uncommenting the line as extension=ext/php_intl.dllin PHP.ini file and restarted my server after.

正如在类似问题中提到的,我已经intl通过取消注释extension=ext/php_intl.dllPHP.ini 文件中的行来启用PHP 扩展,然后重新启动我的服务器。

 $inWords = new \NumberFormatter('en', \NumberFormatter::SPELLOUT);
 echo $inWords->format(1450);

yields the error:

产生错误:

FatalErrorException: Class 'NumberFormatter' not found

FatalErrorException:未找到“NumberFormatter”类

I'm guessing this doesn't have anything to do with Laravel but PHP. Anyone know the solution to the problem? Thanks for your time.

我猜这与 Laravel 无关,但与 PHP 无关。有谁知道问题的解决方案?谢谢你的时间。

回答by Toni

You have to enable the extension in your php.ini by uncommenting the line

您必须通过取消注释该行来启用 php.ini 中的扩展

;extension=php_intl.dll