【问题标题】:How to check if a txt file contain a word [duplicate]如何检查txt文件是否包含单词[重复]
【发布时间】:2016-07-28 18:24:07
【问题描述】:
<?php           
$a = 'grzn.txt';
if (strpos($a, 'word') !== false) 
{
echo 'Found';
}
?>

我如何检查“单词”是否在文本文件“grzn.txt”中? &谢谢

【问题讨论】:

    标签: php


    【解决方案1】:

    您应该在文本内容内搜索,而不是在文件名内搜索。
    使用file_get_contents 函数:

    $a = 'grzn.txt';
    if (strpos(file_get_contents($a), 'word') !== false) echo 'found';
    

    http://php.net/manual/en/function.file-get-contents.php

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-24
      相关资源
      最近更新 更多