サーバーにデータの問題があり、次のようなテキストファイルがたくさんあります。
text1.txt
abc.txt
def.txt
次に、各ファイルから(emp_name)のような特定の単語を含む特定の行を読み取り、phpプロジェクトの全行をエコーする必要があります。これを行う方法は、事前に感謝します。
サーバーにデータの問題があり、次のようなテキストファイルがたくさんあります。
text1.txt
abc.txt
def.txt
次に、各ファイルから(emp_name)のような特定の単語を含む特定の行を読み取り、phpプロジェクトの全行をエコーする必要があります。これを行う方法は、事前に感謝します。
あなたの方向は次のようになります:
1. firstly open the file , through fopen()
2. then by file_get_contents() or fread() to get the content
3. then search for the desired word in the file
編集:
このようにします:
<?php
$data = file_get_contents("input.txt"); //read the file
if(strpos($data,"str_to_find")==false){ //check if string exists in file
echo "str not found";
}
else
echo "str found";
?>