Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php in_数组函数未给出预期结果_Php_Arrays_Newline - Fatal编程技术网

Php in_数组函数未给出预期结果

Php in_数组函数未给出预期结果,php,arrays,newline,Php,Arrays,Newline,我正在使用数组中的来搜索数组中是否存在值。我的代码如下: $file = 'domains.txt'; //reading txt file $lines = file($file);//file in to an array if (in_array("yahoo.com", $lines)) { echo "Got Domain"; } 但是,它不起作用,它只显示一个空白页面,但是yahoo.com在domains.txt中可用,因此它应该返回true,但我无法接受它,请帮助,谢

我正在使用数组中的
来搜索数组中是否存在值。我的代码如下:

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

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

但是,它不起作用,它只显示一个空白页面,但是yahoo.com在domains.txt中可用,因此它应该返回true,但我无法接受它,请帮助,谢谢。

在调用时添加
文件\u IGNORE\u NEW\u line
标志:

当读取yahoo.com的行时,它存储为:

"yahoo.com\n"

上面的标志将告诉您不要将换行符(
\n
)字符附加到返回数组中的每个字符串。

您没有错误检查来确定是否从文件中读取任何内容。这样,您能告诉我为什么要使用
FILE\u IGNORE\u NEW\u LINES
以及我缺少了什么吗?
FILE\u IGNORE\u NEW\u LINES
删除结尾处的换行符
\n
(它出现在每一行新行,哦,奇怪):)不要忘记数组中的大小写敏感度
"yahoo.com\n"