用php搜索文本文件中的短语/单词 [英] Search for phrase/word in text files with php

查看:69
本文介绍了用php搜索文本文件中的短语/单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何扫描特定行文本的目录并列出所有匹配的文件与PHP?

How would I scan a directory for a specific line of text and list all matching files with php?

谢谢。

推荐答案

几天前我实际上写了一个函数...

I actually wrote a function for this a few days ago...

这是扫描的基本功能每个文件...

Here's the base function that scans each file...

foreach (glob("<directory>/*.txt") as $search) {
    $contents = file_get_contents($search);
    if (!strpos($contents, "text")) continue;
    $matches[] = $search;
}

不是最先进的方法,我的功能要长很多也使用我各种其他类的所有功能,这基本上是它所做的。

Not the most advanced way of doing it, my function is much longer but it also uses all functions from my various other classes, this is basically what it does though.

这篇关于用php搜索文本文件中的短语/单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆