If I display $d[0]
it is liam.schnell@gmail.com
but it is refusing to accept th开发者_如何学JAVAe if...
$d = file("mails.txt");
if ($d[0] == "liam.schnell@gmail.com") {
echo "JOW!";
}
echo $d[0];
Any idea?
Try calling the trim function on the $d[0]
, which will remove all new line characters at the beginning and end of the string.
$d = file("mails.txt");
if(trim($d[0])=="liam.schnell@gmail.com"){
echo "JOW!";
}
echo $d[0];
or not include any new lines at all:
$d = file("mails.txt", FILE_IGNORE_NEW_LINES);
if($d[0]=="liam.schnell@gmail.com"){
echo "JOW!";
}
echo $d[0];
Each line in the resulting array will include the line ending, unless FILE_IGNORE_NEW_LINES is used, so you still need to use rtrim() if you do not want the line ending present.
From: http://php.net/manual/en/function.file.php
I agree with Mike Lewis, using trim might fix why it was failing.
Also, in general, if you are having weird results in PHP when comparing strings, try '===' or strcomp to see that fixes the issue.
http://www.phpcatalyst.com/php-compare-strings.php
$d = file("mails.txt", FILE_IGNORE_NEW_LINES);
if ($d[0] == "liam.schnell@gmail.com") {
echo "JOW!";
}
echo $d[0];
精彩评论