将HTML表格的每行每列转为数组,采集表格数据
作者:
未知
来源:
网络收集
整理日期:
2011-05-25
<?
function
get_td_array(
$table
) {
$table
= preg_replace(
"'<table[^>]*?>'si"
,
""
,
$table
);
//开源代码OSPhP.COm.CN
$table
= preg_replace(
"'<tr[^>]*?>'si"
,
""
,
$table
);
$table
= preg_replace(
"'<td[^>]*?>'si"
,
""
,
$table
);
$table
=
str_replace
(
"</tr>"
,
"{tr}"
,
$table
);
//OSPHP.COm.CN
$table
=
str_replace
(
"</td>"
,
"{td}"
,
$table
);
//去掉 HTML 标记
$table
= preg_replace(
"'<[/!]*?[^<>]*?>'si"
,
""
,
$table
);
//OSPHP.com.CN
//去掉空白字符
$table
= preg_replace(
"'([rn])[s]+'"
,
""
,
$table
);
$table
=
str_replace
(
" "
,
""
,
$table
);
//OSPHP.com.CN
$table
=
str_replace
(
" "
,
""
,
$table
);
$table
=
explode
(
'{tr}'
,
$table
);
array_pop
(
$table
);
//OSPHP.com.CN
foreach
(
$table
as
$key
=>
$tr
) {
$td
=
explode
(
'{td}'
,
$tr
);
array_pop
(
$td
);
$td_array
[] =
$td
;
//OsPHP.COM.CN
}
return
$td_array
;
}
?>
责任编辑: webmaster >>> 百度上搜索 谷歌上搜索
点击复制本连接 (http://www.hugesky.com/showarticle.php?id=3197)>>> 相关资讯:
【声明】: 以上文章或资料除注明为电脑技巧原创或编辑整理外,均为网络收集整理或网友推荐。以上内容以共享、参考、研究为目的,不存在任何商业目的。 未注明作者或出处的文章,可能资料来源不规范。如有涉及版权请给予及时联系更正或予以删除。 |