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"