1
我想查找一个文件中存在的字符串(如果存在于另一个文件中)。一个文件中的字符串是否存在于另一个文件中
例如:file.txt的载有以下>
IamLookingforthispatternpleasehelpme
pattern.txt->
thispattern
<?php
if(strpos(file_get_contents("file.txt"),file_get_contents("pattern.txt"))!=FALSE){
echo "found it!!";
}
else{
echo "not able to find";
}
?>
我写上面的代码并运行它但它输出
“无法找到”
如何做到这一点我很新的PHP
并澄清txt文件包含只有上面的格式文本。
echo file_get_contents(“file.txt”)''的输出是什么? 'echo file_get_contents(“pattern.txt”)''的输出是什么?尊重这个警告:http://php.net/manual/en/function.strpos.php,即使用'!== false'而不是'!= false',但是如果模式不在文件的位置0开始.txt,如您的示例所示,这不应该成为您示例中的主要问题。 – stef77
echo file_get_contents(“file.txt”)的输出是“IamLookingforthispatternpleasehelpme”,并且echo file_get_contents(“pattern.txt”)的输出也是正确的 - >“thispattern”。 –
我也用过!==虚假没有成功! –