在PHP中读取文件时忽略大写字母
我正在开发一个程序,它读取一个文本文件,查找一个单词,然后根据是否找到该单词显示不同的结果 有没有办法忽略大写字母?例如,当我寻找一个单词respond时,它会抓住respond,respond,respond,respond等等 代码是:在PHP中读取文件时忽略大写字母,php,if-statement,letters,capslock,Php,If Statement,Letters,Capslock,我正在开发一个程序,它读取一个文本文件,查找一个单词,然后根据是否找到该单词显示不同的结果 有没有办法忽略大写字母?例如,当我寻找一个单词respond时,它会抓住respond,respond,respond,respond等等 代码是: <?php //1 email; $file = "1.txt"; $fh = fopen($file, 'r'); $theData = fread($fh, filesize($file)); fclose($fh); echo "<str
<?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>";
?>
谢谢
$pos = strpos($matches[1], $respond);
应该是:
$pos = stripos($matches[1], $respond);
区分大小写,而不区分大小写。这可能会有所帮助:strpos的不区分大小写版本:如果在模式后面加/i,则它将不区分大小写