fopen之后,我可以在PHP中搜索关键字吗?

发布于 2024-08-19 02:24:10 字数 76 浏览 3 评论 0原文

如果我在文件上使用 fopen ,是否有任何方法可以扫描文件以查找某个关键字开始的字节数?如果没有,我该怎么做?

If I use fopen on a file, is there any way to scan through the file to find the number of bytes a certain keyword begins at? If not, how can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

行至春深 2024-08-26 02:24:10

单程,

$data = file_get_contents("file");
print strpos("$data","myword");

one way,

$data = file_get_contents("file");
print strpos("$data","myword");
你爱我像她 2024-08-26 02:24:10

您表达这个问题的方式听起来像是您正在寻找除基本字符串操作之外的其他东西。如果这就是您的意思 - 不,字符串函数是您唯一的选择。

只需像平常一样获取内容即可。

$content = fread($file_handle, filesize($filename));
$index = strpos($content, 'keyword');

The way you phrase this question makes it sound like you're looking for something other than basic string manipulation. If that's what you're saying - nope, string functions are your only option.

Just get the content as you normally would.

$content = fread($file_handle, filesize($filename));
$index = strpos($content, 'keyword');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文