我想分别将中国时区和其他时区分开 所以想到使用preg match
我认为的想法是
$ pattern = array(" Asia / Shanghai"," Asia / Harbin"," Asia / Chongqing"," Asia / Urumqi&#34 );
$ time_zone =" Asia / Chennai&#34 ;;
所以我想要的是
pregmatch($pattern, $time_zone){
//china time_zone do some operation
}
else{
//rest of the world time zone do some operation.
}
答案 0 :(得分:0)
我相信你的模式应该是:
preg_match("/(Asia\/Shanghai)?(Asia\/Harbin)?(Asia\/Chongqing)?(Asia\/Urumqi)?/", $input_line, $output_array);
http://www.phpliveregex.com/p/f5N
编辑:对不起,我看到我在phpliveregex页面中使用了错误的时区。只需用正确的时区替换$ input_line。EDIT2:我想我应该像你在问题中那样输入它:
$time_zone = "Asia/Chennai";
If(pregmatch("/(Asia\/Shanghai)?(Asia\/Harbin)?(Asia\/Chongqing)?(Asia\/Urumqi)?/", $time_zone)){
//rest of the world time zone do some operation.
}
else{
//china time_zone do some operation
}