user1947455 user1947455 - 6 months ago 55
PHP Question

php simple dom parser how to grab iframe from a class

I am having issues getting the correct iframes from a site.

Here is the code i am trying to use. The problem im having is this returns everything in the content class. I would like to return only the iframes that are located in the class. Any help would be appreciated. Thank you.

$opts = array(
'header'=>"User-Agent: User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.52 Safari/536.5\r\n"

$context = stream_context_create($opts);

$html = file_get_html('', false, $context);

foreach($html->find('.content') as $iframe) {

echo $iframe->outertext, PHP_EOL;



Ok so i figured it out.


$html = file_get_html('');

// find <p> and store varible
foreach($html->find('p') as $p)

// find iframe from within varibale $p
foreach($p->find('iframe') as $iframe)

echo $iframe->outertext . '<p>';

 // clean up memory