2 回答
TA贡献1784条经验 获得超2个赞
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);
TA贡献1851条经验 获得超4个赞
我已经解决了这个问题。下面是我的代码。
$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;
- 2 回答
- 0 关注
- 203 浏览
添加回答
举报