-3

サーバーにデータの問題があり、次のようなテキストファイルがたくさんあります。

text1.txt
abc.txt
def.txt

次に、各ファイルから(emp_name)のような特定の単語を含む特定の行を読み取り、phpプロジェクトの全行をエコーする必要があります。これを行う方法は、事前に感謝します。

4

2 に答える 2

2

あなたの方向は次のようになります:

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";

?>
于 2013-02-03T07:09:20.910 に答える
0

PHPコード:

$myFile = "testFile.txt";
$fh = fopen($myFile, 'r')

単語ごとに読みたい場合

これをチェックしてください

これ

于 2013-02-03T07:07:54.643 に答える