in_array函数没有给出预期的结果

I am using in_array to search in an array if a value exists. My code is below:

$file = 'domains.txt'; //reading txt file
$lines = file($file);//file in to an array

if (in_array("yahoo.com", $lines)) {
    echo "Got Domain";
}

However, its not working, it only displays a blank page, but yahoo.com is available in domains.txt so it should return true, but i am stuck with it, please help, thanks.

Add the FILE_IGNORE_NEW_LINES flag when calling file():

$lines = file($file, FILE_IGNORE_NEW_LINES);

When the line with yahoo.com is being read, it is being stored as:

"yahoo.com
"

The above flag will tells file() not to append the newline () character to each string in the returned array.