Answer the question
In order to leave comments, you need to log in
Setting locale in php under windows to work with UTF-8?
The situation is as follows:
We create a file index.php
in encoding UTF-8
without BOM with the following content:
<?php
header('Content-Type: text/html; charset=UTF8');
var_dump(strftime('Число: %d, месяц: %B, день недели: %A'));
die();
?>
Число: 19, месяц: ������, день недели: �����������
Число: 19, месяц: November, день недели: Monday
setlocale(LC_ALL, 'ru_RU.UTF-8', 'Russian_Russia.65001');
also doesn't change anything. Windows-1251
is , then no problems occur. UTF-8
and make Windows work fine with them. This is real? Answer the question
In order to leave comments, you need to log in
They say under Windows strftime puts on the selected encoding in the locale and works in a single-byte encoding corresponding to the requested language.
It is possible, perhaps, before each similar function (switching the locale to a familiar Windows just in case), recode the input of the function into a single-byte encoding, call it, and then recode the result into utf-8.
setlocale(LC_ALL, "russian");
$day = strftime('%a');
$mon = strftime('%B');
$day = iconv("windows-1251", "UTF-8", $day);
$mon = iconv("windows-1251", "UTF-8", $mon);
<?
$days = array('Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота', 'Воскресенье');
$months = array('Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь');
$nowdate = getdate();
echo 'Число: ', $nowdate['mday'], ', месяц: ', $months[$nowdate['mon']-1], ', день недели: ', $days[$nowdate['wday']-1];
?>
And what about Windows in general? You yourself give functions to UTF-8 input and are surprised that your output is not win-1251. If you want 1251 at the output, then let's use it at the input, at least through the same iconv.
Check with the browser what content_type is _really_ given by the server.
It is quite possible that some settings will override your attempt to give utf8, for example www.php.net/manual/ru/ini.core.php#ini.default-charset or some server settings. And then understand the situation, look for what and where changes.
Unfortunately no. Unreal. Because of the server on Windows, you will have to write a separate wrapper function for any cases of working with dates, currencies, etc.
Example
if ( stripos($u_locale, "1251") !== false ) {
return iconv("windows-1251","utf-8", $date_str);
} elseif (stripos($u_locale, "1252") !== false) {
return iconv("windows-1252","utf-8", $date_str);
} else {
return $date_str;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question