xml - use php to format page into a table -


i trying use following code sort page format of within table, need able extract h4, span , non span name, price, item of table

<?php $c = file_get_contents('http://www.bunnings.com.au/products_category_plumbing-supplies_1637.aspx');  $dom = new domdocument(); $dom->loadhtml($c); $xpath = new domxpath($dom); $div = $xpath->query('//div[@class="details"]'); $div = $div->item(0); echo $dom->savexml($div); ?> 

this simple example put name, price , item number table:

$xpath = new domxpath($dom); $div = $xpath->query('//div[@class="details"]');  echo '<table>';  foreach($div $details) {     $name = $details->getelementsbytagname('h4')->item(0)->getelementsbytagname('a')->item(0)->nodevalue;     $price = $details->getelementsbytagname('p')->item(0)->getelementsbytagname('span')->item(0)->nodevalue;     $itemnumber = $details->getelementsbytagname('p')->item(0)->childnodes->item(2)->nodevalue;      $html = '<tr>';     $html .= '<td>' . htmlspecialchars($name) . '</td>';     $html .= '<td>' . htmlspecialchars($price) . '</td>';     $html .= '<td>' . htmlspecialchars($itemnumber) . '</td>';     $html .= '</tr>';      echo $html; }  echo '</table>'; 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -