So, I'm starting with php and have a trouble with Simple HTML DOM Parser. This is my code so far.
include("simple_html_dom.php");
$html=file_get_html("http://example.com");
foreach($html->find('a') as $links);
$html = file_get_html($links->href);
echo $html;
The main problem is that there are $links instead of one page, that are constantly changing and I don't know how to make computer understand me because I end up with errors and total mess. I will really appreciate any response!
You need some brackets here instead of a semicolon:
foreach($html->find('a') as $links) {
$html = file_get_html($links->href);
echo $html;
}
With the semicolon right after the foreach definition, it won't run anything. If you remove the semicolon, it will still only execute the first line after the loop definition. You need the brackets to group the two statements together.
I don't know how well echoing out the entire HTML for multiple pages in a row will work, though.
You want file_get_html
because file_get_contents
will load the response body into a string but file_get_html
will load it into simple-html-dom.
include("simple_html_dom.php");
$html=file_get_html("http://example.com");
foreach($html->find('a') as $links) {
$html = file_get_html($links->href);
echo $html;
}