PHP Regular Expression extract HTML tag problem

Source: Internet
Author: User
Tags php regular expression
PHP Regular Expression Extract HTML tag problem

<tr> <td height= "> <a class=" Index_libiao "href=" http://www.zh818.com/html/2014/033/7155319.aspx        "Title=" March 14 Shanghai Steel Market Price Summary "target=" _blank "> <font color=" #0000FF "> March 14 Shanghai Steel Market Price Summary </font> </a></td> <td align= "right" ><span class= "Biaotiriqi" > March 14 </span></td> </tr > <tr> <td height= "> <a class=" Index_libiao "href=" http://www.zh818.com/html/2014/033/7155318.        aspx "title=" March 14 Beijing Steel Market Price Summary "target=" _blank "> <font color=" #0000FF "> March 14 Beijing Steel Market Price summary </font> </a></td> <td align= "right" ><span class= "Biaotiriqi" > March 14 </span></td> </t r> <tr> <td height= "" "> <a class=" Index_libiao "href=" http://www.zh818.com/html/2014/033/7155317        . aspx "title=" March 14 Tianjin Steel Market Price Summary "target=" _blank "> <font color=" #0000FF "> March 14 Tianjin Steel Market Price Summary </font> </a></td> &LT;TD align= "right" ><span class= "Biaotiriqi" > March 14 </span></td> </tr> <tr> <td He ight= "> <a class=" Index_libiao "href=" http://www.zh818.com/html/2014/033/7155316.aspx "title=" March 14 Chongqing Steel Market Price Summary "target=" _blank "> <font color=" #0000FF "> March 14 Chongqing Steel Market price Summary </font> </a&gt ;</td> <td align= "right" ><span class= "Biaotiriqi" > March 14 </span></td> </tr> <t r> <td height= "> <a class=" Index_libiao "href=" http://www.zh818.com/html/2014/033/7155315.aspx " title= "March 14 Guangzhou Steel Market Price Summary" target= "_blank" > <font color= "#0000FF" > March 14 Guangzhou Steel Market price Summary </font> &L T;/a></td>

I want to get all the contents of <TD height= ">xxx</td>" in the middle of the label, how should I write the regular expression?

Reply to discussion (solution)

$pattern = "/<td height=\" 30\ "> ([\s\s]*) <\/td>/"; Preg_match_all ($pattern, $str, $matches); Var_dump ($matches);

Testing can be done by

$pattern = "/<td height=\" 30\ "> ([\s\s]*) <\/td>/"; Preg_match_all ($pattern, $str, $matches); Var_dump ($matches);

Testing can be done by
The rules change.

$pattern = "/<td  height=\" 30\ "> ([\s\s]*?) <\/td>/"Preg_match_all ("/<td\s+height=\ "30\" > (. *) <\/td>/ius ", $str, $output);p Rint_r ($output);

The above is the PHP regular expression extract HTML tags of the content of the problem, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

Related articles:

Sample PHP code for extracting HTML tags

Extracting HTML tags from PHP

PHP Regular expression extract image URL program

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