Matching of PHP regular expressions

Source: Internet
Author: User
The main task of matching PHP regular expressions today is to compare the recent upload time of news, research reports, and other consultations with the local time and compare whether the record has exceeded 1 hour, then I programmed php for this.

At the beginning, I thought there was some text information to be processed on the homepage, but I have not found the text information for a long time, at the beginning, I did not find that I had been using regular expressions to process the source code of html. later, I found that it was my own problem, the original html source code does not contain news code. Then I used chrome to search for the page and finally found the url of the news page source. Then process the url.

When processing the url, I directly use a regular expression for processing, but there are various problems during processing. First, the length of the time string may change with time, so at first I didn't know how to handle it. then I tried it for a long time. later, I tried it. * match the text, but because greedy match is used by default in php, a match matches everything, and then I search for it, the solution cannot be found for a long time.

Later, I asked one of my students, who told me that regular expressions use greedy matching by default. this problem can be solved if the pattern can be changed to non-greedy match.

For example, there is a piece of html:

AsdefCcdaAae
Sdc

AsdefDfge
Sdc

. I want to use the rules through preg_match_all

\ S *
Set

AsdefCcdaAae
But PHP does not seem to have any option for non-greedy mode.

AsdefCcdaAae
Sdc

AsdefDfgeBecause the greedy pattern matches
Now

/Regular/U parameter U, the original words in the book are, no longer greedy

Then I finally solved the problem.

 = 3600) {/* compare whether the system time is greater than the last update time of 1 hour. If yes, the system time is incorrect. if not, the system time is correct */echo "this is false
";} Else {echo" this is true
";} Echo $ time ,"
"; Echo $ effecime;} echo" "; if (isset ($ _ POST ['URL']) & $ _ POST ['URL']! = '') {$ Url2 =$ _ POST ['URL']; limittimeindex ($ url2) ;}?>


Http://zhidao.baidu.com/question/110658951.html? Qq-pf-to = pcqq. C2C

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.