Is the setlocale() function in PHP invalid for Chinese?
怪我咯
怪我咯 2017-05-24 11:33:31
0
3
908

Environment:
CentOS 7.3.1611
PHP 7.1.3

Code:

echo setlocale(LC_ALL, array('zh_CN.UTF-8', 'zh_CN.utf8', 'zh_CN')), PHP_EOL;
$date = new DateTime();
echo $date->format('Y-F-d l'), PHP_EOL;

Output:

zh_CN.UTF-8
2017-May-22 Monday

Additional tests, in Shell:

# export LC_ALL=zh_CN.UTF_8
# date
2017年 05月 22日 星期一 19:02:15 CST
# export LC_ALL=en_US.UTF_8
# date
Mon May 22 19:02:34 CST 2017

Question:
It is possible to localize date output in Bash.
Why is it invalid to use the setlocale() function in PHP?

Please give me some advice.

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(3)
大家讲道理

Neither of the above two answers hit the point.
setlocale setlocale
strftimestrftime - Format local time/date according to locale

These two functions must be used together to see the effect.

However, even so, the performance is still different from when you directly call the system bash, and may not necessarily meet your expectations.

过去多啦不再A梦

The date command in bash calls a date application in linux to realize the display and output of the date function

php is the date object and function implemented by itself

It’s quite understandable that the functions of the two are different!

漂亮男人

These are two languages ​​with different method mechanisms. If you are using php里面想得到中文这种格式,完全可以在php中通过exec调用shell’s method:

$cmd = "export LC_ALL=zh_CN.UTF_8 && date";
$date = exec($cmd);
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template