Php preg_使用regex替换以s结尾的单词的撇号

Php preg_使用regex替换以s结尾的单词的撇号,php,regex,preg-replace,Php,Regex,Preg Replace,好的,我正在匹配任何以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

好的,我正在匹配任何以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);
所有的匹配工作,似乎只是它不喜欢的替换。 知道为什么吗


编辑:还有更好的正则表达式来匹配任何包含以S结尾的单词的字符串吗?

这是因为
$with_apos
包含一个
,它会抛出一个错误,尝试使用一个唯一的分隔符。@HamZaDzCyberDeV-如果这是原因-将它作为一个答案转储,这样就可以对它进行投票。lolz,@FoxyFish请做一些努力,bwoebi为您指明了正确的方向,请使用。既然我心情很好,我就给你密码:
$check=preg_quote($check,“#”)$加上_apos=preg_quote($with _apos,“#”)$结果=preg#u replace(#($check|$with_apos)#i“,$1“,$result)谢谢,我以前从来没有使用PrimgSql报价。我建议你考虑一下当$Chice没有用“S”结尾的单词时的情况。现在,它将无法创建$converted变量,从而打乱您运行的查询。
Warning: preg_replace() [function.preg-replace]: Unknown modifier '3'