<meta charset="UTF-8"> <?php $str="Who asks you to read, the fragrance floats when the water falls. http://onestopweb.iteye.com/";//Define the original string //replacing a single keyword $keyword="onestopweb";//Specify the keyword to be replaced echo str_replace($keyword,"<font color=red><b>$keyword</b></font>",$str).'<br>';//加粗加颜色 //If it is a set of keywords, you can loop to determine whether it exists, and the replacement will start when the keyword exists. $keywords = array('chaoyi'=>'<a href="chaoyi">chaoyi</a>','阅'=>'<a href="阅">阅</a>','onestopweb'=>'<a href="onestopweb">onestopweb</a>',); foreach($keywords as $k=>$v){ //strpos cannot judge Chinese if(strstr($str,$k)){ $ str = str_replace ($ k, $ v, $ str); } } echo $str;
Effect picture: