1

我正在开发一个读取文本文件的程序,查找一个单词,然后根据是否找到该单词显示不同的结果。

有没有办法忽略大写字母?因此,例如,当我在寻找一个词响应时,它会抓取响应、响应、响应、响应等。

代码是:

<?php
//1 email;
$file = "1.txt";
$fh = fopen($file, 'r');
$theData = fread($fh, filesize($file));
fclose($fh);

echo "<strong>Email 1 - correct outcome: reply needed <br /></strong>"; 

if (preg_match("/dota(.*?)dota1/s", $theData, $matches))
{
    echo $matches[1]."<br />";
}

$respond   = 'Respond';

$pos = strpos($matches[1], $respond);

if ($pos === false) {
    echo "Reply not needed";
} else {
    echo "Reply needed";

}

echo "<HR>"; 
?>  

谢谢!

4

1 回答 1

3
$pos = strpos($matches[1], $respond);

应该:

$pos = stripos($matches[1], $respond);

strpos()区分大小写,而不stripos()区分大小写。

于 2013-01-12T17:51:12.370 回答