0

The Thai text I want to end up with is: อาทิตย์ 03 มกราคม 2016 to อาทิตย์ ๐๓ มกราคม ๒๐๑๖

I don't think it should matter what language but in this case it is Thai.

My function is:

$strdate = get_thai_date();
print_r($strdate["number"]);

And the output is:

Array (
  [0] => ๐ 

  [1] => ๑

  [2] => ๒ 

  [3] => ๓

  [4] => ๔

  [5] => ๕

  [6] => ๖

  [7] => ๗

  [8] => ๘

  [9] => ๙
)

The input is sunday 03 january 2016 and I am trying to return อาทิตย์ 03 มกราคม 2016, but not อาทิตย์ ๐๓ มกราคม ๒๐๑๖.

Would a function like preg_replace(), strstr() or something else work? Can someone provide an examples?

  • 1
    There's no get_thai_date function in WordPress or in PHP, where is this function coming from and how is it implemented? the same goes for the other variations you mentioned, they're not a part of standard WordPress – Tom J Nowell Jul 13 '18 at 21:35
  • I made get_thai_date(). In functions.php: function get_thai_date() {...} – Dani Jul 13 '18 at 23:35
  • @Dani Can you edit your question to include the code where you wrote the get_thai_date() function please? – DaveLak Jul 13 '18 at 23:36
  • setlocale(LC_TIME, "th_TH.UTF-8"); echo strftime("%A %d %B %Y", strtotime(get_the_date())); $strdate = get_thai_date(); print_r($strdate["number"]); //preg, strstr or others. What to do? – Dani Jul 13 '18 at 23:43
  • function get_thai_date() { $strdate = array ( "number" => array("๐", "๑", "๒", "๓", "๔", "๕", "๖", "๗", "๘", "๙"), //... ) } output Array ( [0] => ๐ [1] => ๑ [2] => ๒ [3] => ๓ [4] => ๔ [5] => ๕ [6] => ๖ [7] => ๗ [8] => ๘ [9] => ๙ ) – Dani Jul 13 '18 at 23:49
0

Update

setlocale(LC_TIME, "th_TH.UTF-8");
echo strftime("%A %d %B %Y", strtotime(get_the_date()));

Before: อาทิตย์ 03 มกราคม 2016

//$strdate = get_thai_date();
//print_r($strdate["number"]); //preg, strstr or others.

//$strdate = date_i18n(...); 

After: อาทิตย์ ๐๓ มกราคม ๒๐๑๖

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.