Regular expression-solve a PHP regular expression matching pattern?

Source: Internet
Author: User
Use cURL to capture a page with a data table and obtain all the cells under TR. use the following method to {code ...} however, the {code...} cannot be matched in two cases ...} and {code ...} I don't know why the cells with many spaces cannot match the cells with class? Because no... capture a page with data tables through cURL, as long as you get all the cells under TR, use the following method

$ Content = content; preg_match_all ('/(.*?) <\/Td>/', $ content, $ res );

However, two cases cannot match

Content

And

Unpaid

I don't know why the cells with many spaces cannot match the cells with class? Because there is no regular expression, a pattern can completely match the TD.
Another problem is that there are two tables on the page. one is used to filter data by various conditions and the other is used to store data. how can we match only the table that stores the data?

Reply content:

Capture a page with a data table through cURL. to obtain all the cells under TR, use the following method:

$ Content = content; preg_match_all ('/(.*?) <\/Td>/', $ content, $ res );

However, two cases cannot match

Content

And

Unpaid

I don't know why the cells with many spaces cannot match the cells with class? Because there is no regular expression, a pattern can completely match the TD.
Another problem is that there are two tables on the page. one is used to filter data by various conditions and the other is used to store data. how can we match only the table that stores the data?

. Line breaks cannot be matched in single row mode.
You can use

\ S matches any blank space character \ S matches any character that is not a blank space character

Match the td with the class.

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

Matching one of the tables is similar. first, match the table from all the contents to an array.

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

Then, let's see the number of times you want to use the regular expression above.

Let's say the opposite!

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

I don't know either. maybe I can.

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.