简体   繁体   中英

setlocale doesn't work with my language, how to create logic about that?

setlocale doesn't work and i tried to create some logic to do what i want:

I have that string string(19) "2017-08-29 11:27:24" I want to get month (08 in that case) to get from array bellow on position 08 aka "Август". And convert it to date again.

$amonths=array('01'=>'Януари','02'=>'Февруари','03'=>'Март','04'=>'Април','05'=>'Май','06'=>'Юни','07'=>'Юли','08'=>'Август','09'=>'Септември','10'=>'Октомври','11'=>'Ноември','12'=>'Декември');

And then to use date('j F Y', some variable) . The result will be "29 Август 2017" not "29 August 2017"

You can replace strings with confidence if you replace the the full month name from English rather than numbers. Something like this will work:

Code: ( Demo )

$lookup=['January'=>'Януари',
        'February'=>'Февруари',
        'March'=>'Март',
        'April'=>'Април',
        'May'=>'Май',
        'June'=>'Юни',
        'July'=>'Юли',
        'August'=>'Август',
        'September'=>'Септември',
        'October'=>'Октомври',
        'November'=>'Ноември',
        'December'=>'Декември'];
$date=date('j F Y',strtotime("2017-08-29 11:27:24"));
echo str_replace(array_keys($lookup),$lookup,$date);

Output:

29 Август 2017

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