当前位置:Gxlcms > PHP教程 > php简单正则有关问题

php简单正则有关问题

时间:2021-07-01 10:21:17 帮助过:12人阅读

php简单正则问题

$timestamp = '2012年02月03 15:06:46';
preg_match_all("/(.*?)年(.*?)/is", $timestamp, $rarr, PREG_SET_ORDER);
print_r($rarr);

preg_match_all("/(.*?)年(.*?)月(.*?) (.*?):(.*?):(.*?)/is", $timestamp, $rarr, PREG_SET_ORDER);
print_r($rarr);
?>


以上代码结尾的那个值总取不到,比如第一个只取到年,取不到月,请问应该如何修改呢?

分享到: 更多


------解决方案--------------------
$timestamp = '2012年02月03 15:06:46';
preg_match_all('/\d+/', $timestamp, $rarr);
print_r($rarr);

------解决方案--------------------
preg_match_all('/[^年^月^\s^\:]+/', $timestamp, $rarr);
------解决方案--------------------
preg_match_all('/[^年^月^\s^\:]+/', $timestamp, $rarr);

人气教程排行