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」。 –
我也用過!==虛假沒有成功! –