在下面的函数中,我想匹配关键字不区分大小写(应该匹配“蓝色瑜伽垫”和“蓝色瑜伽垫”)...
但是,它目前仅在关键字相同大小写时才匹配。
$mykeyword = "蓝色瑜伽垫";
$post->post_content = preg_replace_callback("/\b($mykeyword)\b/","doReplace", $post->post_content);
// the callback function
function doReplace($matches)
{
static $count = 0;
// switch on $count and later increment $count.
switch($count++) {
case 0: return '<b>'.$matches[1].'</b>'; // 1st instance, wrap in bold
case 1: return '<em>'.$matches[1].'</em>'; // 2nd instance, wrap in italics
case 2: return '<u>'.$matches[1].'</u>'; // 3rd instance, wrap in underline
default: return $matches[1]; // don't change others.
}
}