Cyto Posted November 28, 2011 Share Posted November 28, 2011 /*** a new dom object ***/ $dom = new domDocument; /*** load the html into the object ***/ @$dom->loadHTML($file); /*** discard white space ***/ $dom->preserveWhiteSpace = false; /*** the table by its tag name ***/ $tables = $dom->getElementsByTagName('table'); /*** get all rows from the table ***/ $rows = $tables->item(0)->getElementsByTagName('tr'); /*** loop over the table rows ***/ foreach ($rows as $row) { /*** get each column by tag name ***/ $cols = $row->getElementsByTagName('a'); /*** echo the values ***/ echo $cols->item(0)->nodeValue.'<br />'; } Hi, Is there a way to start to echo from 43? thx. Quote Link to comment https://forums.phpfreaks.com/topic/251921-dom-question/ Share on other sites More sharing options...
Psycho Posted November 28, 2011 Share Posted November 28, 2011 I don't work with DOM elements in PHP. I would think there would be a way to get the count of elements in the object but couldn't find a way. If so, that would be the best option as you could simply start at whatever element you wanted. but, this will work. Simply skip the first n elements. /*** loop over the table rows ***/ $startRow = 48; // 49th row $rowNo = 0; foreach ($rows as $row) { if($rowNo>=$startRow) { /*** get each column by tag name ***/ $cols = $row->getElementsByTagName('a'); /*** echo the values ***/ echo $cols->item(0)->nodeValue.'<br />'; } $rowNo++; } Quote Link to comment https://forums.phpfreaks.com/topic/251921-dom-question/#findComment-1291746 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.