Answer the question
In order to leave comments, you need to log in
There is a problem with the encoding of the string returned by the strftime() function. How to fix?
Hello colleagues! I recently encountered the following problem:
I want to display all the names of the months in Russian. To do this, I wrote the following script:
<?php
setlocale(LC_TIME, ''); // во 2-м аргументе "" для того, что бы использовалась локаль системы
echo strftime('%d %Bа %Y');
?>
23 ����а 2018 //а надо 23 марта 2018
<?php
setlocale(LC_TIME, 'ru_RU.UTF-8');
echo strftime('%d %Bа %Y');
?>
23 Marchа 2018
Answer the question
In order to leave comments, you need to log in
Obviously, the locale will not work for anyone, even if you miraculously manage to grope for it, simply because it is required to display "March" instead of "March". So just hardcore
function toRusDate($daystr=null,$format="j F, Y г."){
//print_r($datstr);
if ($daystr) $daystr=strtotime($daystr);
else $daystr=time();
return str_replace( //XXX: нужно проверить английские имена месяцев
array('january','february','march','april','may','june','july',
'august','september','october','november','december'),
array('января','февраля','марта','апреля','мая','июня','июля',
'августа','сентября','октября','ноября','декабря'),
strtolower(date($format,
$daystr)));
}
The fact that the letters are displayed incorrectly in the browser means:
1) the browser has opened a page on which the encoding is not set correctly (something like ). If the encoding is set correctly, but the problem continues to appear, see step 2
2) the reason may be that PHP has already received information in a broken encoding and it cannot normally give it to the browser. in this case, you need to look for the reason in the source of information header('Content-Type: text/html; charset=utf-8')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question