简单的html dom解析器返回所有td的值?

im using simple html dom parser to get scrap some data from html string .
i need to return the TD's values from a table with specific css class each TD as array element
i tried this cod but it gives fetal error

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

then i tried

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

the last one worked good but it brings all TD;s as a single string no each td as an array element ? var_dump result

Array ( 
[0] => 3571 Premium GD 2063199876 Washington Seattle 3703 
)
查看全部
dozc1071
dozc1071
2013/07/17 04:34
  • php
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复