0
我正在局域網內部建立一個小型搜索引擎。因爲只有〜25頁,我使用的是bash腳本這需要的URL列表,並將其格式化爲HTML,例如:如何使preg_quote不區分大小寫?
<div id="result"><p><a href="#">Title 1</a></p><p>Description 1</p></div>
<div id="result"><p><a href="#">Title 2</a></p><p>Description 2</p></div>
然後PHP腳本從的每一行搜索GET輸入以上,並返回每個匹配行。 我的問題,我如何使這個搜索大小寫不敏感?我的PHP代碼如下:
<?php
// index.php
include('inc/header.html');
$searchfor = $_GET['q'];
$file = 'inc/urls.txt';
$contents = file_get_contents($file);
$pattern = preg_quote($searchfor, '/');
$pattern = "/^.*$pattern.*\$/m";
if(preg_match_all($pattern, $contents, $matches)){
echo "<p>Found matches:</p>";
echo implode("<br />", $matches[0]);
}
else{
echo "<p>No matches found.</p>";
fclose ($file);
}
include('inc/footer.html');
?>
我知道這可能是相當明顯的,而且我正在尋找一個/我周圍preg_quote
地方,但我是新來的PHP,似乎無法找到答案,也沒有任何類似的問題上SE/SO/etc
是的,這是謝謝 – jpl42