我使用以下功能搜索文本文件中的单词。问题是此功能区分大小写。我不希望它区分大小写!如何使函数不区分大小写?
$url = 'files/file.txt';
$thedata = file_get_contents($url);
$lines = explode(PHP_EOL, $thedata);
$search = 'some search words';
$pattern = preg_quote($search, '/');
$pattern = "/^.*$pattern.*\$/m";
if(preg_match_all($pattern, $thedata, $matches)) {
echo implode('<br>', $matches[0]);
} else {
echo '<div class="message color-red">';
echo 'Didn\'t find anything on that search!';
echo '</div>';
}
答案 0 :(得分:2)
除了模式字符串中最后i
之后的m
之外,添加/
:
$pattern = "/^.*$pattern.*\$/mi"