2013-01-12 48 views
1

我正在研究一個讀取文本文件,查找單詞,然後根據單詞是否顯示不同結果的程序。從PHP中的文件中讀取時忽略大寫字母

有沒有辦法忽略大寫字母?因此,例如,當我在尋找一個字迴應會搶反應,反應,反應,響應等

代碼是:

<?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>"; 
?> 

謝謝!

+1

這可能有助於:不區分大小寫的strpos版本:http://php.net/manual/en/function.stripos.php – DWright

+1

如果您將/ i放在模式後面,它將不區分大小寫 –

回答

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

應該是:

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

strpos()是大小寫敏感的,而stripos()是不區分大小寫的。

+1

stripos和/ i是兩個工作,謝謝你們! :) – dmae

相關問題