0

(Linux)
In the following program I'm trying to process the file accounts.txt line by line searching for a match to the form supplied variable '$email'. The function fgets() is stepping though the file line by line correctly but my attempts at using preg_match() and or strpos() to determine if that line contains the string contained in '$email' have failed. Any ideas or suggestions? Thanks.

<?php

$email = $_POST['email'];
$psswd = $_POST['psswd'];

echo "The email address is $email<br>";
echo "The password is $psswd<br><br>";

$file = fopen("./accounts.txt", 'r+') or die("Failed to open file");

while(!feof($file))
{
    $line = fgets($file);
    if(preg_match($email, $line))
    {
        echo "There was a match";
    }
    else
    {
        echo "There was not match";
    }

    //echo "$line<br>";
}
//$line = fgets(preg_match($email, '$file'));


fclose($file);

?>
2
Contributors
3
Replies
16
Views
3 Years
Discussion Span
Last Post by lewashby
0

Code for reading file:

<?php
$file = fopen("members.txt", "r");
$members = array();

while (!feof($file)) {
   $members[] = fgets($file);
}

fclose($file);

var_dump($members);
?>

The function returns the following values:

int strcmp ($string1, $string2);

Returns < 0 if string1 is less than string2.
Returns > 0 if string1 is greater than string2.
Returns 0 if they are equal.

0

My program is stepping through the file line by line correctly, what I can't seem to be able to do is determine if the string supplied by the '$email' variable is a substring in the current line being processed.

0

I also got this error doing it that way.

[error] [client 127.0.0.1] PHP Notice: Array to string conversion in /var/www/ET/password/accounts.php on line 16

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.