Hello, I've run in to a problem with a PHP script using SimpleHTMLDOM to pull a list of URLs of a page.
If I specify the URL I want to read the links off, the script gives me no problems:
$url='http://www.example.com';
$blogpost = file_get_html($url);
foreach ($blogpost->find('a[href*=example1]') as $example1link) {
$example1link = $example1link->href;
echo $example1link;
}
All this does is pull from www.example.com all the links to www.example1.com and echo it back to me.
But when I try to feed the script a text file with URLs:
$urlarray = split("\n", file_get_contents('urls.txt'));
foreach ($urlarray as $url) {
$blogpost = file_get_html($url);
foreach ($blogpost->find('a[href*=example1]') as $example1link) {
$example1link = $example1link->href;
echo $example1link;
}
}
It gives me the following error:
Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty
in simple_html_dom.php on line 39
For those that don't have simple_html_dom.php this is the function the error refers to:
function file_get_html() {
$dom = new simple_html_dom;
$args = func_get_args();
$dom->load(call_user_func_array('file_get_contents', $args), true);
return $dom;
}
I can even echo $url right before I assign the value to $blogpost. The problem seems to be in passing the $url variable to file_get_html(). But only when I use a txt file with target links to scrape.
I'm very new to PHP (and programming in general) and I've searched around almost all day and cannot find what I'm doing wrong.
Any help is appreciated.
Thanks!