Home > Backend Development > PHP Tutorial > 问个简单的有关问题

问个简单的有关问题

WBOY
Release: 2016-06-13 13:38:58
Original
928 people have browsed it

问个简单的问题
有一大串字符串:

的群威群胆我亲亲我期望的期望驱动器位丢弃武器2011-12-12读取读取驱动器位前雾灯期望12321321321dadada


如何截取其中的时间?

PS:如果不用正则的话。有没有什么str函数?

------解决方案--------------------
/(\d+-\d+-\d+)/
------解决方案--------------------
$str = "的群威群胆我亲亲我期望的期望驱动器位丢弃武器2011-12-12读取读取驱动器位前雾灯期望12321321321dadada";
$pattern = "/(\d{4}-\d{1,2}-\d{1,2})/";

preg_match_all( $pattern, $str, $matches);
echo '

';<br>print_r($matches);<br>?>
<br><font color="#e78608">------解决方案--------------------</font><br>字符串方法  不过太局限了,日期前不能出现'-',还是用正则吧
Copy after login
PHP code
$str='的群威群胆我亲亲我期望的期望驱动器位丢弃武器2011-12-12读取读取驱动器位前雾灯期望12321321321dadada';
$position=strpos($str,'-')-4;
echo substr($str,$position,10); <div class="clear">
                 
              
              
        
            </div>
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