我想把中国时区和其他时区分开,所以我想用preg match。
我的想法是
$pattern =array(“亚洲/上海”,“亚洲/哈尔滨”,“亚洲/重庆”,“亚洲/乌鲁木齐”);
$time_zone =“亚洲/金奈”;
所以我想要的是
pregmatch($pattern, $time_zone){
//china time_zone do some operation
}
else{
//rest of the world time zone do some operation.
}发布于 2016-03-26 15:49:15
我相信你的模式应该是这样的:
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
}https://stackoverflow.com/questions/36232889
复制相似问题