View Single Post
Old 03-09-2012, 09:25 AM  
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,619
Quote:
Originally Posted by Brujah View Post
I want to expand on #2 post, so you can see a working example.

Code:
$html = '<h1 class="video-title one two clearfloat">get this</h1>';

$dom = new DOMDocument();

$dom->loadHTML( $html );

$xpath = new DOMXpath( $dom );

$h1 = $xpath->query( '//h1[contains(@class,"video-title")]' );

var_dump( $h1->item(0)->nodeValue );
DOM is so much better for parsing/scraping once you figure out how to use xpath queries. I had to use "contains(@class,"video-title")" in the above query because the class actually contains more than just 'video-title'
i actually timed it, the preg match is faster
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


My Newest Theme
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote