2011-11-18 94 views
0

所以我有一個大表(701行,19列)。我需要提取每個td中的內聯字母,然後將其寫入一個csv。問題是,這需要永遠。只做100次,需要32秒。這是我的代碼:尋找TD Innertext,可以簡化嗎?

for ($j = 0; $j < 100; $j++) 
    { 
     $f = $html->find("td",$j); // get the td elements from the html 
     $rowArray[] = $f->innertext; // store that text inside the array 

     if(($j+1) % 19 == 0) // hit the end of the row 
     { 
      $txt .= implode(",", $rowArray) . "\r\n"; // format with comma's and throw it into $txt 
      unset($rowArray); // clear the array, for the next record    
      $rowArray = array(); // re-set the array 
     } 
    } 

的100是一個臨時值,而我的測試,它確實是接近13000。最大的問題是找到TD值。有沒有更快的方式,或者這是我可以得到它的好?

基本上,尋找從HTML表格中提取TD數據的最快捷方式,以便我可以將其寫入CSV。

+0

我會嘗試寫入文件,因爲我解析每一行。參見[fwrite](http://php.net/manual/en/function.fwrite.php#refsect1-function.fwrite-notes)。 (**編輯**我想要上面那一節。) – fncomp

+0

發佈HTML表格 - 雖然它不如HTML解析,你可以使用正則表達式來拉取所有你需要的內容。 – nickb

+0

該表存儲在.txt文件中,但基本上它都被刪除。所以唯一的標籤是

​​。 701ish行,每行19列。 regex會比簡單的HTML DOM更快嗎? – jsquadrilla

回答

0

做了一個str_replace來獲取我不想要的東西,並且能夠更快更快地獲取內容。