好的,所以我匹配以 S 结尾的任何单词,并将其替换为'S 进行mysql搜索,一切正常..
$check = "string to tests";
if(preg_match("/s\b/", $check)) {
preg_match("/s\b/", $check, $match);
$no_apos = $match[0];
$with_apos = str_replace($no_apos, "'s", $check);
$converted = "LIKE '%$check%' OR subject LIKE '%$with_apos%'";
}
$search_result = mysql_query("SELECT * FROM db WHERE subject $converted ORDER BY subject ASC");
$result = preg_replace("#($check|$with_apos)#i", "<span style='background-color:#EEEE00'>$1</span>", $result);
但是我在获取结果时收到此错误:
Warning: preg_replace() [function.preg-replace]: Unknown modifier '3'
所有匹配工作,它似乎只是它不喜欢的替换。 知道为什么吗?
编辑:还有一个更好的正则表达式匹配包含以S结尾的单词的任何字符串吗?