Jump to content

file_get_contents()


dcole.ath.cx

Recommended Posts

I'm having problems with this part of the script:$content = file_get_contents("$todourls[0]");it says:Warning: file_get_contents(http://www.w3schools.com ) [function.file-get-contents]: failed to open stream: No error in C:\xampp\htdocs\xampp\search\gcache.php on line 34but it works if the $todourls[0]; is the one and only URL from $todourls array... how can this be?

Link to post
Share on other sites

The argument passed to the function get_file_contents() is meanted to be $todourls[0], but like this, it reads a string with the variable in blue: "$todourls[0]". It can be either this:$todourls[0]or this:"{$todourls[0]}"with the first one not defining a string but a variable, and the later one saying "everyting in these braces is one variable" :)

Link to post
Share on other sites

forgot about the quotes... I'm trying my best not to do that, but as you can see I did it again.just tested it again... and again with a whole bunch of URLsand still got this message for each URL:Warning: file_get_contents(http://dcole.ath.cx ) [function.file-get-contents]: failed to open stream: No error in C:\xampp\htdocs\xampp\search\gcache.php on line 34

Link to post
Share on other sites

Well it goes though a for loop 100 times, each time opening a file and getting the first line and putting it into that statement I'm having problem with, then afterwards it deletes the first line... then it's ready for the file to be opened again (so it will have a new line)

Link to post
Share on other sites

You can't use file_get_contents() with URLs usually. If you want to get the stuff for a webpage use file() instead of file_get_contents;so it would look like this(ish):

<?php$todourls[]="http://jhechtf.sytes.net/";$todourls[]="http://www.w3schools.com/";foreach($todourls as $value){$file  = join('',file($value));//$file is the contents of the webpage passed through the function.. do whatever u want now.}?>

Link to post
Share on other sites

You can use file_get_contents(), file_get_contents() puts the data into a string, vs. file() which put's it into an array.---- ---well the solution was that there was an extra space formed after the each URL if there was more than one URL, most likely caused by the exploding of the data... if you look at the error message you will notice the extra space in the quotes after the URL.

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...