Get all class elements from html code as a text file using php

advertisements

I'm trying to get all span elements with class="msgsource" from my website's html code and then send it to the browser to download as a .txt file. this is what I have, but it download an empty text file

<?php
// parse div content
include('simple_html_dom.php');
$html = file_get_html('http://www.example.com');
$code = $html->find('[@class="msgsource"]');
$content = $code->outertext;

// send content to browser
header("Content-Type: application/force-download");
header("Content-Length: " . sizeof($content));
header('Content-Disposition: attachment; filename=mylog.txt');
echo $content;
?>


<?php
// parse div content
include('simple_html_dom.php');
$html = file_get_html('http://simplehtmldom.sourceforge.net/manual.htm');
$code = $html->find('span[class=comment]');
echo count($code);
echo $code[1];
?>

Use this format to find html elements :

 $code = $html->find('span[class=comment]');

The resultant will be stored in $code as an array and then access individual array elements (html element text contents) using their indexes.