John_S Posted March 5, 2009 Share Posted March 5, 2009 Hello everybody, I have a little problem with a small part of code: $users = file("users.db.php"); foreach ($users as $line) { if(!eregi("<\?php",$line)) { $user = explode('|', $line); echo $user[0]."\n".$user[1]."\n".$user[2]."\n".$user[3]."\n".$user[4]; } } I am trying to get out all lines from a file except all lines that start with <?php, the problem is... it doesn't work, it doesn't print anything at all. In that file (users.db.php) I have the following code: <?php die("Access Restricted. You are not allowed to access this file"); ?> Id|Username|Password|Permissions|Last Logged In|Email|Registered| Could somebody tell me please where is my mistake? Thanks a lot in advance! Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 5, 2009 Share Posted March 5, 2009 Your code works fine for me. I used the code you provided and created a test.php file, then created a (users.db.php) file with the content you showed. The output I received when running the test php file is Id Username Password Permissions Last Logged In You should get an error if the file name or path are incorrect. Are you poistive you don't have two versions of users.db.php floating around? Try running just this code to ensure you are reading the file $users = file("users.db.php"); $lineno = 1; foreach ($users as $line) { $user = explode('|', $line); echo "Line $lineno: $line\n"; $lineno++; } Quote Link to comment Share on other sites More sharing options...
John_S Posted March 5, 2009 Author Share Posted March 5, 2009 Your code works fine for me. I used the code you provided and created a test.php file, then created a (users.db.php) file with the content you showed. The output I received when running the test php file is Id Username Password Permissions Last Logged In You should get an error if the file name or path are incorrect. Are you poistive you don't have two versions of users.db.php floating around? Try running just this code to ensure you are reading the file $users = file("users.db.php"); $lineno = 1; foreach ($users as $line) { $user = explode('|', $line); echo "Line $lineno: $line "; $lineno++; } Hello there, When I run your code, I receive this : Line 1: <?php die("Access Restricted. You are not allowed to access this file"); ?> Id|Username|Password|Permissions|Last Logged In|Email|Registered| Seems weird to me actually. And when myself I execute my script I got a blank browser window => no output at all. Might it be because the content is "technically" on the same line? (In my editor I see it on two lines but it might be on one if there isn't a proper ) EDIT: Thanks a lot! Your part of code made me realize that two pices <?php... and id|username... were "technically" on the same line since I had "\n"s everywhere but not "\r"s. So even thought I saw the code in my editor being on two different lines, it wasn't like that in the file itself. 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.