upgrader Posted May 30, 2009 Share Posted May 30, 2009 Hi there I have wrote the code below to search the table on the URL and pick out the name value in rows 2-4, however it is not very efficient as it still does a foreach on every single row. $html = file_get_contents('http://badhausen.hlstatsx.com/?mode=players&game=css'); $dom = new domDocument; $dom->loadHTML($html); $dom->preserveWhiteSpace = false; $tables = $dom->getElementsbyTagName('table'); $rows = $tables->item(->getElementsByTagName('tr'); $count = 1; foreach ($rows as $row) { if($count >= 2 && $count <=4) { $cols = $row->getElementsByTagName('td'); echo "<li>".$cols->item(1)->nodeValue.'</li>'; } $count++; } How could I optimise it? Link to comment https://forums.phpfreaks.com/topic/160312-domdocument-code-optimization/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.