简体   繁体   中英

PHP setlocale does not work for Korean language

I am currently using date function to print out today's date. While doing this, I realized that the setlocale function does not work for Korean unfortunately so I am now wondering is there any way to directly translate from English to Korean through one to one mapping.

so currently I have

setlocale(LC_CTYPE, 'ko_KR,eucKR');
$today = date("Y년 m월 d일 l", strtotime('today'));

This prints 2014년 9월 12일 Monday and I would like to change Monday to 월.

So instead of relying on setlocale I want to know if it is possible to directly change this like:

Monday => 월 etc.

Setlocale returns identifier of local that has been set ("new current locale"). Check what it returns to you.

Later, you can check if desired locale is installed in your system. Example for GNU/Linux:

$ locale -a

I'm guessing that you don't have the korean locale installed on the system that is running the scripts. You can still just append the correct word for the day at the end of your formatted date.

<?php

$days = array(
         '일',
         '월',
         '화',
         '수',
         '목',
         '금',
         '토'
        );

$today = date("Y년 m월 d일 w", strtotime('today'));
$today = substr_replace($today, $days[substr($today, -1)], -1);

echo $today;

Output (at time of writing):

2014년 09월 12일 금
                 ^ friday

date('w') returns a number representing each day of the week from 0 (Sunday) to 6 (Saturday).

You can create an array:

<?php 
$kor_day = array( '일', '월', '화', '수', '목', '금', '토' );
echo $kor_day[date('w')];
?>

It will output the day of the week in Korean.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM