我有这个.php文件,它从.txt文件中搜索文本并将其与用户输入的内容进行比较。我不知道如何让它对.txt文件进行不区分大小写的搜索
<?php
$search = $_POST['search'];
$text = file_get_contents('name_list.txt');
$lines = explode("\n", $text);
if(in_array($_POST['search'], $lines)){
echo stristr($search, " is compatible!");
} else {
echo stristr($search, " is not compatible!");
}
?>
以下是与之链接的JavaScript:
$(function() {
$(".search_button").click(function() {
var searchString = $("#search_box").val();
var data = 'search='+ searchString;
if(searchString) {
// ajax call
$.ajax({
type: "POST",
url: "do_search.php",
data: data,
beforeSend: function(html) {
$("#results").html('');
$("#searchresults").show();
$(".word").html(searchString);
},
success: function(html){
$("#results").show();
$("#results").append(html);
}
});
}
return false;
});
});
任何帮助/意见表示赞赏。
答案 0 :(得分:0)
我会比较搜索的非大写版本和文本文件:
<?php
$search = $_POST['search'];
$search_lower = strtolower($search); // make the search lowercase
$text = file_get_contents('name_list.txt');
$text = strtolower($text); // make the text lowercase
$lines = explode("\n", $text);
if(in_array($search_lower, $lines)){
echo $search . " is compatible!";
} else {
echo $search . " is not compatible!";
}
答案 1 :(得分:0)