【发布时间】:2019-03-05 15:40:21
【问题描述】:
我遇到了一个奇怪的 PHP 函数 strpos()。 我有一个函数可以检查是否在 txt 文件中找到传递的字符串。 我可以逐行显示文件的内容,但 strpos() 不返回值(实际上什么都没有)。 var_dump() 的返回空。
有人能看出错误吗,因为我迷路了。 提前谢谢你。
我的功能:
function checkIfExist($string)
{
$path = "\\\\server\\temp\\test.txt";
$file = file($path);
foreach( $file as $line )
{
echo $line; //display the string in this line
$found = strpos($file,$string);
echo $found; //display nothing, not even a boolean/int
}
return $found;
}
【问题讨论】:
-
看起来您是在文件的整个内容中而不是在每一行中查找字符串。根据
$string的内容和您可能无法匹配的文件。