Question

  • My development environment is: Win7, XAMPP 1.8.3.3 VC11.
  • include_path in my PHP.ini file is: ".;C:\xampp\php\PEAR"

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.

Was it helpful?

Solution

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');

OTHER TIPS

You probably mean http://www.google.com and not a file called www.google.com

you need to use http:// with url

<?php
include_once('simplehtmldom_1_5/simple_html_dom.php');
echo file_get_html('http://www.google.com')->plaintext;
?>

also you need to check you have file dir(simplehtmldom_1_5) on where test1.php located like :-

C:\xampp\htdocs\simplehtmldom_1_5
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top