dcole.ath.cx Posted August 19, 2006 Share Posted August 19, 2006 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 comment Share on other sites More sharing options...
Little Goat Posted August 19, 2006 Share Posted August 19, 2006 take the quotes out, or put curly brackets {} around the variable. Link to comment Share on other sites More sharing options...
Jack McKalling Posted August 19, 2006 Share Posted August 19, 2006 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 comment Share on other sites More sharing options...
dcole.ath.cx Posted August 20, 2006 Author Share Posted August 20, 2006 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 comment Share on other sites More sharing options...
SFB Posted August 20, 2006 Share Posted August 20, 2006 . Link to comment Share on other sites More sharing options...
dcole.ath.cx Posted August 20, 2006 Author Share Posted August 20, 2006 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 comment Share on other sites More sharing options...
SFB Posted August 20, 2006 Share Posted August 20, 2006 . Link to comment Share on other sites More sharing options...
dcole.ath.cx Posted August 20, 2006 Author Share Posted August 20, 2006 Sry SFB, but I gave you enough information... way more then you really needed... My first post had like twice the information you needed.The problem has been solved! Link to comment Share on other sites More sharing options...
jhecht Posted August 20, 2006 Share Posted August 20, 2006 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 comment Share on other sites More sharing options...
dcole.ath.cx Posted August 20, 2006 Author Share Posted August 20, 2006 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 comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now