<?php 
$str="hello,中国人!"; 
$keyword="中";
$str=str_replace($keyword," <font color=red>".$keyword." </font>",$str); 
$keyword="人";
$str=str_replace($keyword," <font color=red>".$keyword." </font>",$str); 
echo $str; 
?> 
或者
<?php 
$str="hello,中国人!"; 
$keyword="中国人"; 
$str=str_replace($keyword," <font color=red>中</font>国<font color=red>人</font>".$str); 
echo $str; 
?> 
如果只是要搜索"中"和"人"中间有字的结果那就用正则表达式好了

解决方案 »

  1.   

    ob_start("highlight_callback");......
    ob_end_flush();
      

  2.   

    $str=str_replace($keyword,"  <font color=red>中 </font>国 <font color=red>人 </font>".$str);  
    楼上的这个写错了哦
    最后的那个应该是逗号,
      

  3.   


    $str="中国人";
    $keyword=array('中','人');
    $repalce=array('<font color="red">中</font>','<font color="red">人</font>');
    echo str_replace($keyword,$repalce,$str);