To ask a simple question, there is a large string: GroupWise, I personally expected the desired drive bit discard weapon 2011-12-12 read the drive bit fog lamp and expected 12321310821dadada how to intercept the time in it? PS: If regular expressions are not used. Is there any str function ?, /(\ D +-\ d +)/, & lt ;? Php $ str: a simple question
There is a large string:
GroupWise, I personally expected the desired drive bit discard weapon read the drive bit fog lamp expected 12321321321 dadada
How to extract the time?
PS: If regular expressions are not used. Is there any str function?
------ Solution --------------------
/(\ D +-\ d + )/
------ Solution --------------------
$ Str = "Awesome! I personally expected the desired drive bit discard weapon read the drive bit fog lamp expected 12321321321 dadada ";
$ Pattern = "/(\ d {4}-\ d {1, 2}-\ d {1, 2 })/";
Preg_match_all ($ pattern, $ str, $ matches );
Echo'
';
Print_r ($ matches );
?>
------ Solution --------------------
The string method is too limited. '-' cannot appear before the date. use regular expressions.
PHP code
$ Str = 'awesome group' I personally expect the desired drive bit discard weapon 2011-12-12 read the drive bit fog lamp expect 12321310921dadada '; $ position = strpos ($ str,'-')-4; echo substr ($ str, $ position, 10 );