Jump to content
Sign in to follow this  
ludo1960

getting started with domdocument

Recommended Posts

Hi guys,

Just starting to play with PHP Domdocument, only to fail at the very first step:

<?php   

$html = 'test/php/somefile.html' ;

if(!empty($html)){  

      $dom_1 = new domDocument ; 
      $dom_1->loadHTML($html) ; 
      $links = $dom_1->getElementsByTagName('li') ;

      foreach ( $links as $link) {
			// echo $link ;
           echo $link->nodeValue, PHP_EOL;
      }  
}
?>

When I visit it in a browser I get a WSOD, what am I missing?

Share this post


Link to post
Share on other sites

You did not read the documentation. The variable $html is not an HTML string which is what loadHTML expects. You want 'loadHTMLFile' instead.

Share this post


Link to post
Share on other sites

oops, all good now. Thanks for pointing me in the right direction, off to play now and I promise to read the manual :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.