Regular expression-solves a PHP regular match pattern?

Source: Internet
Author: User
Grab a page with a datasheet with curl, just get all the cells under TR and use the following method

$content = 内容;preg_match_all('/(.*?)<\/td>/',$content,$res);

But there are two things that can't be matched.

                            内容                                    

And

            未付                                                                                                                    

Don't know why cells with a lot of space and cells with class can't match? Because there is no regular, a pattern can be fully matched out of TD.
There is also a problem with two table on the page. One for various conditions to filter the data, a hold the data, how to match the data only the table?

Reply content:

Grab a page with a datasheet with curl, just get all the cells under TR and use the following method

$content = 内容;preg_match_all('/(.*?)<\/td>/',$content,$res);

But there are two things that can't be matched.

                            内容                                    

And

            未付                                                                                                                    

Don't know why cells with a lot of space and cells with class can't match? Because there is no regular, a pattern can be fully matched out of TD.
There is also a problem with two table on the page. One for various conditions to filter the data, a hold the data, how to match the data only the table?

The line break cannot be matched in single-line mode.
You can use

\s匹配任意的空白符\S匹配任意不是空白符的字符

Extrapolate, match TD with Class.

/
  
   
    
   ([\s\S]+?)<\/td>/
  
   

Match one of the table's, the same extrapolate Ah, first from all the contents of the table into an array.

/
  
   
    
   ([\s\S]+?)<\/table>/
  
   

Then see you want the first few, and then use the above regular match again not good.

Or that sentence, extrapolate Ah!

$pattern = "/
  
   
    
   ([\s\S]*?)<\/td>/";
  
   

I don't think so.

  • 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.