标签:
<?php $contents = ‘<tr class=""> <td>508982</td> <td>08,07,01,03,04,09,05,10,06,02</td> <td>2015-08-31 17:17</td> </tr> <tr class="odd"> <td>508981</td> <td>02,03,06,04,10,05,09,01,08,07</td> <td>2015-08-31 17:12</td> </tr>‘; preg_match_all(‘/<tr([\s\S]*?)>([\s\S]*?)<\/tr>/‘,$contents,$matched); foreach($matched[2] as $k=>$v){ preg_match_all(‘/<td>([\s\S]*?)<\/td>/‘,$v,$matched_v); print_r($matched_v); }
结果
Array ( [0] => Array ( [0] => <td>508982</td> [1] => <td>08,07,01,03,04,09,05,10,06,02</td> [2] => <td>2015-08-31 17:17</td> ) [1] => Array ( [0] => 508982 [1] => 08,07,01,03,04,09,05,10,06,02 [2] => 2015-08-31 17:17 ) ) Array ( [0] => Array ( [0] => <td>508981</td> [1] => <td>02,03,06,04,10,05,09,01,08,07</td> [2] => <td>2015-08-31 17:12</td> ) [1] => Array ( [0] => 508981 [1] => 02,03,06,04,10,05,09,01,08,07 [2] => 2015-08-31 17:12 ) )
参考:
http://www.5idev.com/p-php_preg_match.shtml
http://www.5idev.com/p-php_regular_syntax_1.shtml
http://www.5idev.com/p-php_regular_syntax_2.shtml
标签:
原文地址:http://www.cnblogs.com/walter371/p/4774171.html