Home > Backend Development > PHP Tutorial > php简单正则问题

php简单正则问题

WBOY
Release: 2016-06-23 14:39:08
Original
912 people have browsed it

<?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);?>
Copy after login


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


回复讨论(解决方案)

$timestamp = '2012年02月03 15:06:46';preg_match_all('/\d+/', $timestamp, $rarr);print_r($rarr);
Copy after login

preg_match_all('/[^年^月^\s^\:]+/', $timestamp, $rarr);

preg_match_all('/[^年^月^\s^\:]+/', $timestamp, $rarr);
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template