找到TD Innertext,这可以简化吗?

时间:2011-11-18 04:43:45

标签: php csv simple-html-dom innertext

所以我有一张大桌子(701-ish行,19列)。我需要在每个td中提取innertext,然后将其写入csv。问题是,这需要永远。只做100,需要32秒。这是我的代码:

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。

1 个答案:

答案 0 :(得分:0)

是否有一个str_replace来获取我不想要的东西,并且能够更快更快地获取内容。