码迷,mamicode.com
首页 > Web开发 > 详细

php正则表达式获取表格内容

时间:2015-08-31 23:06:38      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:

<?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

php正则表达式获取表格内容

标签:

原文地址:http://www.cnblogs.com/walter371/p/4774171.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!