所以,我試圖在文本文件中搜索特定的單詞/值。在大小寫敏感的PHP搜索?
目前,我只能搜索它區分大小寫。
這裏是我的代碼:
<html>
<?php
\t //$searchthis = "ignore this";
\t $matches = array();
\t $FileW = fopen('result.txt', 'w');
\t $handle = @fopen("textfile.txt", "r");
\t ini_set('memory_limit', '-1');
\t if ($handle)
\t {
\t \t while (!feof($handle))
\t \t {
\t \t \t $buffer = fgets($handle);
\t \t \t if(strpos($buffer, $_POST["search"]) != FALSE)
\t \t \t \t $matches[] = $buffer;
\t \t }
\t \t fwrite($FileW, print_r($matches, TRUE));
\t \t fclose($handle);
\t }
\t print 'Found Possible Matches, here are the results' ."\n";
\t sleep(2);
\t //show results:
\t sleep(10);
?>
\t </br>
<?php
$file = "result.txt";
$text = file_get_contents($file);
$text = nl2br($text);
echo $text;
?>
</html>
所以,與其這樣:
查詢搜索:casesensiTiveworD 結果:沒有
時,有一個值textfile.txt即「casesensitiveword」
我希望它這樣做:搜索
查詢:casesensiTiveworD
結果:Casesensitiveword
但我不知道如何做到這一點,我會很感激任何幫助,我我一直試圖找出這個小時,現在我不能。
使用[stripos函數](HTTP: //php.net/manual/en/function.stripos.php) – Thamilan