【问题标题】:How to displaying all data from all file_get_contents & search one of them [closed]如何显示来自所有 file_get_contents 的所有数据并搜索其中一个 [关闭]
【发布时间】:2018-07-23 10:05:39
【问题描述】:

我有一些txt文件,使用file_get_contents()函数只显示一个文件。

如果我想在每个文件中找到一个对象,那么我必须一个一个地打开文件并使用 ctrl + f 搜索它。

我认为这不是从所有现有文件中搜索对象的有效方法。

谁能建议我如何创建“搜索功能”来搜索某些 txt 文件中的对象?

我使用 php 脚本。

this is txt file

【问题讨论】:

  • 您必须使用scandir() 并将所有结果放入一个数组中。放置所有路径并爬入它的子文件夹的子文件夹。之后,您可以在该数组中找到文件(带路径)。
  • 你能给出示例代码吗?

标签: php html file-get-contents


【解决方案1】:

创建一个scandir来列出文件,然后使用file_get_contents查找内容并使用

【讨论】:

  • 你能给出示例代码吗?
  • $q = "find_this"; $dir = "你的目录"; $files = scandir($dir); foreach($files as $file){ $sContent = file_get_contents($dir."/".$file); if (stripos($q,$sContent) !== false){ echo $file."\n"; } }
  • 对不起,反向 stripos 参数
猜你喜欢
  • 2013-10-15
  • 1970-01-01
  • 2016-06-24
  • 2016-04-10
  • 1970-01-01
  • 2012-05-30
  • 1970-01-01
  • 1970-01-01
  • 2014-01-23
相关资源
最近更新 更多