我试过的代码 -
<?php
$htmlContent = '<table border="1" cellpadding="5"><tr bgcolor="E0E0E0">
<th>Process Name
<th>Process ID
<th>Protocol
<th>Local Port
<th>Local Port Name
<th>Local Address
<th>Remote Port
<th>Remote Port Name
<th>Remote Address
<th>Remote Host Name
<th>State
<th>Process Path
<th>Product Name
<th>File Description
<th>File Version
<th>Company
<th>Process Created On
<th>User Name
<th>Process Services
<th>Process Attributes
<th>Added On
<th>Module Filename
<th>Remote IP Country
<th>Window Title
<tr><td bgcolor=#FFFFF0 nowrap>Unknown<td bgcolor=#FFFDF0 nowrap>0<td bgcolor=#FFFCF0 nowrap>TCP<td bgcolor=#FFFBF0 nowrap>5357<td bgcolor=#FFF9F0 nowrap>wsd<td bgcolor=#FFF8F0 nowrap>127.0.0.1<td bgcolor=#FFF7F0 nowrap>49159<td bgcolor=#FFF5F0 nowrap> <td bgcolor=#FFF4F0 nowrap>127.0.0.1<td bgcolor=#FFF3F0 nowrap>SYSTEM-PC<td bgcolor=#FFF1F0 nowrap>Time Wait<td bgcolor=#FFF0F0 nowrap> <td bgcolor=#FEF0F0 nowrap> <td bgcolor=#FDF0F1 nowrap> <td bgcolor=#FBF0F3 nowrap> <td bgcolor=#FAF0F4 nowrap> <td bgcolor=#F9F0F5 nowrap>N/A<td bgcolor=#F7F0F7 nowrap> <td bgcolor=#F6F0F8 nowrap> <td bgcolor=#F5F0F9 nowrap> <td bgcolor=#F3F0FB nowrap>10/5/2017 5:36:00 PM<td bgcolor=#F2F0FC nowrap> <td bgcolor=#F1F0FD nowrap> <td bgcolor=#F0F0FF nowrap>
</table>
';
$DOM = new DOMDocument();
$DOM->loadHTML($htmlContent);
$Header = $DOM->getElementsByTagName('th');
$Detail = $DOM->getElementsByTagName('td');
//#Get header name of the table
foreach($Detail as $NodeHeader)
{
$aDataTableHeaderHTML[] = trim($NodeHeader->textContent);
}
print_r($aDataTableHeaderHTML);
die();
?>
是否可以过滤或仅显示部分<th>
字段。
上面的代码以增量顺序创建,排列和添加它,并以适当的格式记录。
存储数组后,是否可以在引导表中显示过滤后的数据。