Strftime not working online

Hi
I’m using a simple fuction to get a date time like this :
<?php echo strftime("%d %B %Y",strtotime($tit)); ?>

This is working locally but not online : special characters are written with �

Do you know what kind of settings I have to set on the servor ? I’m running on OVH with PHP 7.0

1 Like

What is your locale setting? Is the locale supported on the server?

You can get a list of supported locales with

locale -a

If special characters are not rendered correctly, then there’s probably a problem with UTF-8 encoding.

Here is my locale settings

c::set('locale', array(
  LC_COLLATE  => 'fr_FR.utf8',
  LC_MONETARY => 'fr_FR.utf8',
  LC_NUMERIC  => 'fr_FR.utf8',
  LC_TIME     => 'fr_FR.utf8',
  LC_MESSAGES => 'fr_FR.utf8',
  LC_CTYPE    => 'fr_FRs.utf8',
));
c::set('locale', 'fr_FR.utf8');
c::set('date.handler', 'strftime');
c::set('date.timezone', 'Europe/Paris');

To get the list with supported locales, do I have to do <?php echo locale -a; ?> ? (Sorry I don’t know how to do)

No, you would type that into a terminal when on your server…

Ok, well simple as hell, I did it quickly. I obtained a long list of UFT8, and inside :

fr_FR
fr_FR.ISO8859-1
fr_FR.ISO8859-15
fr_FR.UTF-8

Does that mean I have to replace fr_FR.utf8 to fr_FR.UTF-8 ?

Yes, please try that.

If it works, you can use different config.php files for local and remote.

Nope, doesn’t work, I set :

c::set('locale', array(
  LC_COLLATE  => 'fr_FR.UTF-8',
  LC_MONETARY => 'fr_FR.UTF-8',
  LC_NUMERIC  => 'fr_FR.UTF-8',
  LC_TIME     => 'fr_FR.UTF-8',
  LC_MESSAGES => 'fr_FR.UTF-8',
  LC_CTYPE    => 'fr_FRs.UTF-8',
));
c::set('locale', 'fr_FR.UTF-8');
c::set('date.handler', 'strftime');
c::set('date.timezone', 'Europe/Paris');
1 Like

Try to put this line into your php.ini or .htaccess:

AddDefaultCharset UTF-8

Please also check if the mb_string extension is installed on the server.

Ok, this was my fault, I forget my controller which had a line setlocale(LC_ALL, 'fr_FR');, I changed it to setlocale(LC_ALL, 'fr_FR.UTF-8');, and it’s working now.

Thank you very much for quickly replied to me, have a nice evening :slight_smile:

You are welcome, have a nice evening as well :slightly_smiling_face:.