Anim9or Posted October 9, 2008 Share Posted October 9, 2008 Hi, I was wondering if sanyone could help me with the fopen tool. I'm tring to open a certain number of files, and pront out a specific line from them. However, the function only seems to work when a single number is given. If you use a variable, it will only access the first varaible number, even after the varaible is augmented. Here is the code: for ($read=0;$read<=$z;$read++) { $File2 = 'images/data/$read.txt'; $file[$read] = @fopen($File2, "r"); while($lines<3){ $line[$lines]=fgets($file[$read]); $lines++; } echo "<br>$read"; echo "<br>$File2"; echo "<br>$line[1]"; fclose($file[$read]); } Thanks! Quote Link to comment Share on other sites More sharing options...
Barand Posted October 9, 2008 Share Posted October 9, 2008 try resetting $lines to 0 before the while loop Quote Link to comment Share on other sites More sharing options...
BillyBoB Posted October 9, 2008 Share Posted October 9, 2008 Could you post more code? Most of the variables aren't set in your code. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted October 9, 2008 Share Posted October 9, 2008 Variables aren't expanded when enclosed in single quotes: <?php $File2 = 'images/data/$read.txt'; ?> so you probably want <?php $File2 = "images/data/$read.txt"; ?> or <?php $File2 = 'images/data/' . $read . '.txt'; ?> Ken Quote Link to comment Share on other sites More sharing options...
Anim9or Posted October 9, 2008 Author Share Posted October 9, 2008 I got it working, I'm not sure what it was exactly since it worked when i changed the while loop to s for loop, but I think it was in fact the "$lines" variable not resetting. Thanks everyone's quick responses Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.