I'm using this code to check if the entered email is existe or not in text file
$handle = fopen("http://mywebsite/u.txt", "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
$line = preg_replace('/\s+/', ' ', $line);
if($line=$email){
echo "email existe";
}
}
fclose($handle);
} else {
// error opening the file.
}
the output is the same for exsiting emails and not exsiting email in the text file
email existeemail existeemail existe
the text file contains as a test emails
- test@test.com
- hello@world.com
- test@t.com
if i did == it didn't enter the condition when the $line = $email
trying with
echo $line." ".$email;
OUTPUT
test@test.com test@test.comtest@test.com test@test.comtest@test.com test@test.com
if($line=$email)
< is an assignment and will always be TRUE. You're looking forif($line==$email)
with an extra=
. Give that a try. If it works, there's a duplicate for this.trim()
both the line and the email to make sure there's no whitespace/new linesvar_dump($line);
after your preg_replace, it still has a space after it..htaccess
, you can allow only your server to access the file and not let anyone else get access. See this answer and this Q&A which could be of help. And you're welcome :) Glad to know things worked out.