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.

anonym
  • 4,460
  • 12
  • 45
  • 75
  • 2
    see under `phpinfo` it shows it ? also try to run `php -m` to see successfully loaded extensions. – jagad89 May 21 '17 at 10:21
  • 1
    Have you restarted webserver after enabling `intl`? Do you see `intl` in `phpinfo()`? – u_mulder May 21 '17 at 10:21
  • 1
    Possible duplicate of [Fatal error: Class 'NumberFormatter' not found](http://stackoverflow.com/questions/30554177/fatal-error-class-numberformatter-not-found) – Sandeesh May 21 '17 at 10:23
  • `php -m` shows `intl` extension in the list, but I can't find any `intl` in phpInfo. What should I look for there? I did restart the server but without success. – anonym May 21 '17 at 10:25
  • 1
    make suer you edited same `php.ini` file which shows in `phpinfo` page. – jagad89 May 21 '17 at 10:34
  • Restarting Apache server didn't work, but restarting my PC did. Now `phpinfo()` shows `intl version 1.1.0` in the list and the code works as well. Thanks a lot for help. – anonym May 21 '17 at 10:35

2 Answers2

6

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

;extension=php_intl.dll
Toni
  • 670
  • 11
  • 29
5

You need to use

use \NumberFormatter;

At controller

Nazmul Haque
  • 720
  • 8
  • 13
  • 1
    This is the answer that worked for me. Laravel was complaining 'Class "App\Helpers\NumberFormatter" not found.' use NumberFormatter; also works. – GTS Joe Aug 09 '22 at 22:45