简体   繁体   中英

Class 'NumberFormatter' not found in Laravel 5.4

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

1450 -> One Thousand Four Hundred and Fifty

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

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

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

yields the error:

FatalErrorException: Class 'NumberFormatter' not found

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.

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

;extension=php_intl.dll

You need to use

use \NumberFormatter;

At controller

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM