preg_match_all("#\[mycode\](.+?)\[/mycode\]#is",$content,$matchs,PREG_SET_ORDER); for($i=0;$i<=count($matchs);$i++) { $content=preg_replace("#\[mycode\](.+?)\[/mycode\]#is",highlight_string($matchs[$i][1]),$content,1); }