我在我的服务器有一个数据diractory并没有像如何读取在PHP中一个txt文件
text1.txt
abc.txt
def.txt
现在我需要阅读包含特定单词就像一个特定的行多个文本文件(EMP_NAME)从每个文件,并在我的PHP项目回声全行。 如何做到这一点任何帮助表示感谢提前。
我在我的服务器有一个数据diractory并没有像如何读取在PHP中一个txt文件
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";
?>
你事先知道文件名是什么,或者这是否改变? – Floris
有很多方法可以读取一行,但我需要读取包含特定单词的行 – Shawon
ya我知道文件名 – Shawon