即時通訊使用簡單的HTML DOM解析器來從HTML字符串中獲取一些數據。
我需要從表中具有特定的CSS類的每個TD返回TD的值作爲數組元素
我想這鱈魚,但它給胎兒錯誤簡單的html dom解析器返回所有td的值?
<?php
include('classes/simple_html_dom.php');
$html = str_get_html('<table class="pages_navigator">
<tr>
<th style="width:50px;">ID </th>
<th>Business </th>
<th style="width:70px;">Category</th>
<th style="width:50px;">Phone </th>
<th style="width:70px;">State</th>
<th style="width:70px;">City</th>
<tr class="users_tr">
<td>3571</td>
<td>Premium GD</td>
<td>2063199876</td>
<td>Washington</td>
<td>Seattle</td>
<td>3703</td>
</tr>
</table>');
$tds = $html->find('table.pages_navigator')->find('td') ;
print_r($tds);
?>
然後我試圖
<?php
include('classes/simple_html_dom.php');
$html = str_get_html('<table class="pages_navigator">
<tr>
<th style="width:50px;">ID </th>
<th>Business </th>
<th style="width:70px;">Category</th>
<th style="width:50px;">Phone </th>
<th style="width:70px;">State</th>
<th style="width:70px;">City</th>
<tr class="users_tr">
<td>3571</td>
<td>Premium GD</td>
<td>2063199876</td>
<td>Washington</td>
<td>Seattle</td>
<td>3703</td>
</tr>
</table>');
$result = array();
foreach($html->find('tr.users_tr') as $e){
$result[] = $e->plaintext . '<br>';
}
print_r($result);
?>
的最後一個工作正常,但它將所有TD; s作爲單個字符串,每個td都沒有作爲數組元素? 的var_dump結果
Array (
[0] => 3571 Premium GD 2063199876 Washington Seattle 3703
)
請加什麼打印$結果? –
@VaheShadunts新增 –
你可以var_dump($ e)? –