<?PHP$a=Array( ' Lufax ', ' favorable net ', ' chit-fortune ');$b=Array( ' <a href= ' http://www.baidu1.com > Lufax </a> ', ' <a href= ' http://www.baidu2.com ' > favorable net </a> ', ' <a href= "http://www.baidu3.com" > Fortune </a> ');$str= ' There is a friend reported that the CCTV named the stock market risk, and pointed out that the Lufax, favorable network, the network of wealth peer net loan more secure. The great God of wealth is the lufax of security. ‘;EchoStr_replace_limit ($a,$b,$str, 1);//functions that limit the number of replacementsfunctionStr_replace_limit ($search,$replace,$subject,$limit=-1) { if(Is_array($search)) { foreach($search as $k=$v) { $search[$k] = "".Preg_quote($search[$k], ""). '; } } Else { $search= "".Preg_quote($search, "). '; } return Preg_replace($search,$replace,$subject,$limit);}?>
Str_replace to limit the number of replacements