php正则表达式获取表格内容
2015-08-31 21:26
561 查看
<?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大力力 [040节] 买了一天域名,整了一天后台,新网后台不懂啊
- php设置教程
- php分页类
- PhpStorm注册码
- 启用php-fpm状态详解
- Ubuntu编译安装 GD以及PHP
- php curl 简介
- PHP获取数组中最大的值及其对应的键值
- php二维数组去重
- php电商系统iwebshop二次开发教程第一讲《iwebshop框架结构》
- php获取远程图片并把它保存到本地
- 常见的PHP设计模式
- CURLOPT_TIMEOUT_MS之php版本支持
- php 类中数组与静态方法的配合使用
- PHP 导出Excel 文档
- php安装不了 sqlserver 解决办法 mssql.dll php_sqlsvr_55_ts.dll
- 中兴412/460扩展命令(FTP、端口速率)
- php self this 区别
- php curl的几个例子【转】
- 配置NTP,同步服务器时间