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> <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> ;</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