我想用锚标记替换可用字符串中的一些单词。但这给我带来了问题。我正在做如下:
$post['Post']['comment'] = 'a class href';
$post['Post']['person'] = 'a';
$post['Post']['place'] = 'class';
$post['Post']['thing'] = 'href';
$thing = "<a class='searchName' href='javascript:void(0)'>".ucfirst($post['Post']['thing'])."</a>";
$person = "<a class='searchName' href='javascript:void(0)'>".ucfirst($post['Post']['person'])."</a>";
$place = "<a class='searchName' href='javascript:void(0)'>".ucfirst($post['Post']['place'])."</a>";
$search_strings = array($person=>$post['Post']['person'],$place=>$post['Post']['place'],$thing=>$post['Post']['thing']);
$kw_to_search_for = $post['Post']['comment'];
foreach($search_strings as $key=>$v)
{
if (preg_match('~\b' . $v . '\b~i', $kw_to_search_for, $m))
{
$as[] = str_ireplace($v, $key, $kw_to_search_for);
}
}
上述代码的输出是:
Array
(
[0] => **A** cl**A**ss href
[1] => a **Class** href
[2] => a class **Href**
)
但我不想像上面那样输出。根据我的要求,输出应如下所示:
Array
(
[0] => **A** class href
[1] => a **Class** href
[2] => a class **Href**
)
请尽快建议.......