Ask a simple question

Source: Internet
Author: User
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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.