jasteele123

parse_html.php

Dec 2nd, 2011
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.58 KB | None | 0 0
  1. <?php /* parse_html.php */
  2. /**
  3.  * Parse (possibly) badly formed HTML
  4.  *
  5.  * SimpleXML: http://php.net/simplexml
  6.  * DomDocument: http://php.net/manual/en/class.domdocument.php
  7.  */
  8. $html = file_get_contents('http://somesite.com/');
  9.   // create a new DOMDocument and set strictErrorChecking to FALSE
  10. $dom = new DOMDocument();
  11. $dom->strictErrorChecking = FALSE;
  12.   // load the (probably dodgy) HTML into the DOMDocument
  13. $dom->loadHTML($html);
  14.   // load the DOMDocument into SimpleXML
  15. $obj = simplexml_import_dom($dom);
  16.   // examine it
  17. echo '<xmp>'. print_r($obj, 1). '</xmp>';
  18. ?>
  19.  
Advertisement
Add Comment
Please, Sign In to add comment