Jump to content

[SOLVED] REGEX Problem.


John_S

Recommended Posts

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!  :)

Link to comment
Share on other sites

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++;
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.