2017-07-02 293 views
0

我使用這個庫:http://simplehtmldom.sourceforge.net/manual.htmSimpleHTMLDom圖書館

我有以下的頁面,我想在每行提取:

<div class="amx-form-entry-container"> 
      <table style="font-size: 16px; color:#000"> 
       <tbody><tr> 
        <td>Submitted by:</td> 
        <td> 
         Rami 
        </td> 
       </tr> 
       <tr> 
        <td> 
         Assignee: 
        </td> 
        <td> </td> 
       </tr> 
       <tr> 
        <td> 
         Subcategory: 
        </td> 
        <td> H: Documentation</td> 
       </tr> 
       <tr> 
        <td> 
         Description: 
        </td> 
        <td>Hello</td> 
       </tr> 
       <tr> 
        <td> 
         Case reference: 
        </td> 
        <td> 
         BEY/0517/4444 

        </td> 
       </tr> 
       <tr> 
        <td> 
         Status: 
        </td> 
        <td> Closed</td> 
       </tr> 
       <tr> 
        <td> 
         Created on: 
        </td> 
        <td> 19 May 2017</td> 
       </tr> 

      </tbody></table> 
     </div> 

例如:拉米
申請人:
由Submited: ..
描述:你好

我已經完成了這段代碼: $oDom = new simple_html_dom(); $dd=$oDom->load($result); $test= $oDom->find("div[class='amx-module amx-mr-form-panel']",0); echo $test;

但它打印輸出作爲表,如果我查看頁面源,我會看到相同的上面的代碼。 - 我想要實現的是將每個元素打印在一行中。

回答

0

這裏是我的代碼

$oDom->load($result); 
$tables = $oDom->find('table'); 

$theData = array(); 
foreach($tables[0]->find('tr') as $row){ 
    $rowData = array(); 
    foreach($row->find('td') as $cell) { 
     $rowData[] = $cell->innertext; 
    } 
    $theData[] = $rowData; 
} 
echo "<pre>"; print_r($theData); echo "</pre>"; 


### Result ### 

Array 
(
[0] => Array 
    (
     [0] => Submitted by: 
     [1] => Rami      
    ) 
[1] => Array 
    (
     [0] => Assignee:      
     [1] => 
    ) 
[2] => Array 
    (
     [0] => Subcategory:      
     [1] => H: Documentation 
    ) 
[3] => Array 
    (
     [0] => Description:      
     [1] => Hello 
    ) 
[4] => Array 
    (
     [0] => Case reference:      
     [1] => BEY/0517/4444       
    ) 
[5] => Array 
    (
     [0] => Status:      
     [1] => Closed 
    ) 
[6] => Array 
    (
     [0] => Created on:      
     [1] => 19 May 2017 
    ) 
) 
+0

感謝親愛的,它的工作! – Petr