You can use fgetcsv() directly
$string = " user_email@something.com "; $filename = "user_email.txt"; $h = fopen("$filename","r"); $flag=0; while (!feof ($h)) { list($username, $email= fgetcsv($h); if ($string == $email) { /* do something */ } }
fgetcsv() (as a good side effect) also removes the "field fields" (double quotes " ) for you if they exist.
Your own example probably doesn't work, because if you have such a line
"username", "email"
splitting at will result in
'"username"' ' "email"'
Pay attention to the spaces before the "email" that you forgot to delete. The additional use of str_replace() to remove surrounding quotes is rather unsafe. Take a look at trim() .
King crunch
source share