如何在php中标记搜索词

如何在php中标记搜索词,php,Php,如何在php中标记搜索词 下面的代码将小写字母替换为大写字母,反之亦然 比如,如果搜索词是samsung,那么结果是samsung Galaxy S4,或者如果 搜索词是AP,结果是Apple。 请帮忙 $high=$searchTerm $repl=''$高", $out=preg_replace('/('.$high')/i',$repl,$adtitle) 我重复$out这将突出显示您的术语,同时保留原始案例 $high = preg_quote($searchTerm); $out =

如何在php中标记搜索词

下面的代码将小写字母替换为大写字母,反之亦然 比如,如果搜索词是samsung,那么结果是samsung Galaxy S4,或者如果 搜索词是AP,结果是Apple。 请帮忙

$high=$searchTerm
$repl=''$高",
$out=preg_replace('/('.$high')/i',$repl,$adtitle)


我重复$out

这将突出显示您的术语,同时保留原始案例

$high = preg_quote($searchTerm);
$out = preg_replace("~$high~i", '<span class="hilite">\0</span>', $adtitle);
$high=preg_quote($searchTerm);
$out=preg_replace(“~$high~i”,'\0',$adtitle);
或者,如果您想尊重单词边界:

$high = preg_quote($searchTerm);
$out = preg_replace("/\b$high\b/i", '<span class="hilite">\0</span>', $adtitle);
$high=preg_quote($searchTerm);
$out=preg_replace(“/\b$high\b/i”、“\0”、$adtitle);

据我所知,您希望显示结果,而不考虑其情况


如果是这样,请尝试将您的查询更改为
LOWER(column)和LOWER(term)
,以便首先从数据库返回它们。

您是指文本框中的自动提示吗?不,我的网页中有搜索引擎。我正在使用LIKE query@andrieandrei