0

I'm trying to use the IntlDateFormatter class to format date and time strings to local (Dutch) time formats. I use the following code that I copy-pasted from https://www.simonholywell.com/post/2015/07/international-php-dates-with-intl/ into my Main class:

$DateTime = new DateTime();
$IntlDateFormatter = new IntlDateFormatter(
    'es_ES',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL
);
echo $IntlDateFormatter->format($DateTime);

But I get the following errors:

Fatal error: Uncaught Error: Class 'IntlDateFormatter' not found in C:\Users\denni\PhpstormProjects\ACNOP OOP\Main.php on line 69

Error: Class 'IntlDateFormatter' not found in C:\Users\denni\PhpstormProjects\ACNOP OOP\Main.php on line 69

I already tried to uncomment the line ;extension=php_intl.dll so that it becomes extension=php_intl.dll, but that did not help. What do I need to do? I use PHPStorm, just in case if that is important

Thanks in advance.

Community
  • 1
  • 1
Arkhana
  • 33
  • 1
  • 8
  • 2
    Are you using Windows? Have you restarted the web server after enabling the extension? – M. Eriksson Jul 01 '18 at 13:30
  • After having enabled a module in php you need to restart the processes using that configuration. So you might have to restart either the http server if you use php as a module inside or a separate server like fastcgi or fpm if you chose that path to integrate php with the http server. Either way you need to make sure the process is restarted. Then go and check using the `phpinfo()` method if the module is actually loaded. If not check your http servers error log file. – arkascha Jul 01 '18 at 13:36
  • @MagnusEriksson Do you know any other operating system that use a path notation like `C:\Users\...`? – arkascha Jul 01 '18 at 13:37
  • Restarting PHPstorm fixed the error. Thanks! – Arkhana Jul 01 '18 at 14:25
  • @arkascha - I have no idea how, but for some reason I totally missed that... – M. Eriksson Jul 01 '18 at 15:07
  • How do I set this question on solved? – Arkhana Jul 30 '18 at 21:04
  • Does this answer your question? [Fatal error: Class 'IntlDateFormatter' not found](https://stackoverflow.com/questions/6242378/fatal-error-class-intldateformatter-not-found) – mdfst13 Apr 09 '23 at 23:50

2 Answers2

0

it is necessary to go on xampp, apache, config, to seek PHP (php.ini) click on it, then to seek (;extension=intl), to withdraw the ';' then to record. return on apache in xampp and stop then start. return on your page the problem must be solved

0

Note that the OP has already noted that the solution was actually to restart Apache, which fixed the OP's situation. However, this asks for an alternative to enabling in php.ini, and there actually is one.

If you are creating a software package for deployment on systems you don't manage, there is an alternative to editing php.ini. You can use the Symfony version of IntlDateFormatter. With some editing, this can be modified to run in your application and solve the missing class error.

Note: this solution only makes sense if you cannot edit php.ini (if necessary copy the ICU files into Apache) and restart Apache. Otherwise, the "with some editing" portion of this makes the whole thing more complicated than just enabling intl. So people with the OP's problem should make sure that they've done all three things: edit the correct php.ini; copy the ICU files into Apache; restart Apache. See Fatal error: Class 'IntlDateFormatter' not found for more information on that solution.

People who find this useful should upvote this answer to How to use IntlDateFormatter in Symfony?. That provided an important missing step.

mdfst13
  • 850
  • 8
  • 18