我想生成搜索结果所有大写字母或小字母,但现在它只显示确切的关键字结果,因此我将原始代码$pattern = "/".$searchTerm."([a-zA-Z0-9])*/";
更改为此$pattern = "/".$searchTerm."([a-zA-Za-ZA-z0-9])*/";
但是这会显示一些错误并且输出不会出现
错误:
警告:preg_match_all():编译失败:范围乱序 在/var/app/current/WS/search.php中的偏移量为14的字符类 30
警告:为foreach()提供的参数无效 第31行/var/app/current/WS/search.php { “消息”: “成功”, “响应”:1, “结果”:[]}
我的搜索代码:
if($searchTerm&&$searchType)
{
if($searchType=='hash') {
$query = "SELECT hashTag FROM `".$table."` WHERE hashTag LIKE '%#".$searchTerm."%'";
$stmt = $database->prepare($query);
// $stmt->bind_param('s',$searchTerm);
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows>0) {
$tempArray = array();
$stmt->bind_result($hashTag);
while ($row =$stmt->fetch()) {
$pattern = "/".$searchTerm."([a-zA-Za-ZA-z0-9])*/";
preg_match_all($pattern,$hashTag,$matches);
foreach ($matches[0] as $key => $value) {
$finalArray[$value] = "";
}
}
foreach ($finalArray as $key => $value) {
$tempArray = array();
$tempArray['hash'] = $key ;
array_push($megaArray, $tempArray);
}
$stmt->free_result();
$stmt->close();
$finalArray = array();
$finalArray = $megaArray;
$message = "success";
$response = 1;
}
}
为搜索字词生成结果的解决方案是大写还是小?