I have downloaded a package simplehtmldom_1_5 and kept in "C:\xampp\php\PEAR" folder so that my test file "C:\xampp\htdocs\test1.php" can include PHP files from this package. My test1.php looks like:
<?php
include_once('simplehtmldom_1_5/simple_html_dom.php');
echo file_get_html('www.google.com')->plaintext;
?>
As soon as I type http://localhost/test1.php
, I get the below error:
Warning: file_get_contents(www.google.com): failed to open stream: No such file or directory in C:\xampp\php\pear\simplehtmldom_1_5\simple_html_dom.php on line 75
Notice: Trying to get property of non-object in C:\xampp\htdocs\test1.php on line 15
If I move the simplehtmldom_1_5 package from "C:\xampp\php\PEAR" to "C:\xampp\htdocs\simplehtmldom_1_5" and then try the above test1.php, I get the below error:
Warning: file_get_contents(www.google.com): failed to open stream: No such file or directory in C:\xampp\htdocs\simplehtmldom_1_5\simple_html_dom.php on line 75
Notice: Trying to get property of non-object in C:\xampp\htdocs\test1.php on line 15
I have spent considerable time in debugging this but gave up now. Please help where I am wrong.
When using file_get_contents
or similar function to open a URL you should specify the full protocol to tell PHP this is web address or external file not a local file.
Therefore,
file_get_contents('www.google.com')
Should be changed to:
file_get_contents('http://www.google.com');