php將HTML表格每行每列轉(zhuǎn)為數(shù)組實現(xiàn)采集表格數(shù)據(jù)的方法
來源:易賢網(wǎng) 閱讀:1936 次 日期:2015-04-07 14:30:38
溫馨提示:易賢網(wǎng)小編為您整理了“php將HTML表格每行每列轉(zhuǎn)為數(shù)組實現(xiàn)采集表格數(shù)據(jù)的方法”,方便廣大網(wǎng)友查閱!

本文實例講述了php將HTML表格每行每列轉(zhuǎn)為數(shù)組實現(xiàn)采集表格數(shù)據(jù)的方法。分享給大家供大家參考。具體如下:

下面的php代碼可以將HTML表格的每行每列轉(zhuǎn)為數(shù)組,采集表格數(shù)據(jù)

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

}

?>

更多信息請查看IT技術(shù)專欄

更多信息請查看網(wǎng)絡(luò)編程
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點

版權(quán)所有:易賢網(wǎng)