PHP将HTML表格的每行每列转为数组,采集表格数据
2014-04-09 00:00
411 查看
<?php
function get_td_array($table) {
$table = preg_replace("'<table[^>]*?>'si","",$table);
$table = preg_replace("'<tr[^>]*?>'si","",$table);
$table = preg_replace("'<td[^>]*?>'si","",$table);
$table = str_replace("</tr>","{tr}",$table);
$table = str_replace("</td>","{td}",$table);
//去掉 HTML 标记
$table = preg_replace("'<[/!]*?[^<>]*?>'si","",$table);
//去掉空白字符
$table = preg_replace("'([rn])[s]+'","",$table);
$table = str_replace(" ","",$table);
$table = str_replace(" ","",$table);
$table = explode('{tr}', $table);
array_pop($table);
foreach ($table as $key=>$tr) {
$td = explode('{td}', $tr);
array_pop($td);
$td_array[] = $td;
}
return $td_array;
}
?>
function get_td_array($table) {
$table = preg_replace("'<table[^>]*?>'si","",$table);
$table = preg_replace("'<tr[^>]*?>'si","",$table);
$table = preg_replace("'<td[^>]*?>'si","",$table);
$table = str_replace("</tr>","{tr}",$table);
$table = str_replace("</td>","{td}",$table);
//去掉 HTML 标记
$table = preg_replace("'<[/!]*?[^<>]*?>'si","",$table);
//去掉空白字符
$table = preg_replace("'([rn])[s]+'","",$table);
$table = str_replace(" ","",$table);
$table = str_replace(" ","",$table);
$table = explode('{tr}', $table);
array_pop($table);
foreach ($table as $key=>$tr) {
$td = explode('{td}', $tr);
array_pop($td);
$td_array[] = $td;
}
return $td_array;
}
?>
相关文章推荐
- php将HTML表格每行每列转为数组实现采集表格数据的方法
- 将HTML表格的每行每列转为数组,采集表格数据
- 将HTML表格的每行每列转为数组,采集表格数据
- 将php数组输出html表格的方法
- 将php数组输出html表格的方法
- php实现的一个很好用HTML解析器类可用于采集数据
- php实现的一个很好用HTML解析器类可用于采集数据
- php把从数据库读取出来的数据存放到数组里,然后数组不能直接使用,要转为字符串
- php实现的一个很好用HTML解析器类可用于采集数据
- 将PHP数组输出为HTML表格
- 数据采集利器-PHP用DOM方式处理HTML之《Simple HTML DOM》
- 数据采集利器-PHP用DOM方式处理HTML之《Simple HTML DOM》
- php查询到多条数据结果后,将每一条结果放入数组
- PHP获取表单数据与HTML嵌入PHP脚本的实现
- PHP 在接收POST大数据(大数组或大字符串)时出现500错误
- php表单,HTML表单提交后,返回,保留表单数据
- php获取数组中重复数据
- html与js和php间数据交互
- DataFrame 将某列数据转为数组的方法
- 【细说PHP学习】第九章 PHP中的数组与数据结构