doumu4032
2019-07-30 13:26
浏览 142
已采纳

如何使用PHP将泰语日期转换为英语?

Currently i am doing format of date from THAI To English Language but it could not format date from THAI to English. I researched on Google but i could not found anything over there.

Following is my THAI date formate

15 กรกฎาคม 2562

图片转代码服务由CSDN问答提供 功能建议

目前我正在从 THAI English 语言但无法将日期从 THAI 格式化为 English 。 我研究过 Google ,但我找不到任何东西。

以下是我的THAI日期格式

  15กรกฎาคม2562 
   
 
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • duanhuilao0787 2019-07-30 13:40
    已采纳

    One solution with str_replace

    <?php
    $search = [
        // Here thai months from 1 to 6
        'กรกฎาคม',
        // And the rest here
    ];
    $replace = [
        // Here eng months from 1 to 6
        'July',
        // And the rest here
    ];
    
    $tdate = '15 กรกฎาคม 2562';
    $edate = str_replace($search, $replace, $tdate);
    
    var_dump($edate);
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • doulan8330 2019-07-30 14:09

    replace your word with thai word by making an array

     $pairs = ["กรกฎาคม"=>"july", "month"=>"englishmonth", "three"=>"one"];
    
        $r = preg_replace_callback(
            "/\w+/",                           # only match whole words
            function($m) use ($pairs) {
                if (isset($pairs[$m[0]])) {     # optional: strtolower
                    return $pairs[$m[0]];      
                }
                else {
                    return $m[0];              # keep unreplaced
                }
            },
            $source
        );
    
    评论
    解决 无用
    打赏 举报
  • dsl2014 2019-07-30 15:48

    Thanks you guys. I have solved this issues. Below is my code.

    $date = explode(" " , "15 กรกฎาคม 2562");
    $EnglishYear = $date[2] - 543;
    $testKey = '';
    $monthNamesThai = array("มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน",
    "กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤษจิกายน","ธันวาคม");
    $monthNameEnglish = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    foreach($monthNamesThai as $key => $monthNamesThai){
        if($date[1] == $monthNamesThai){
            $testKey = $key;
        }
    }
    $resultDate = $date[0]." ".$monthNameEnglish[$testKey]." ".$EnglishYear;
    echo $resultDate;
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题