This checks and caches the first substring position in one command, next replacing it if present, should be the more compact and performant:
if(($offset=strpos($string,$replaced))!==false){
$string=substr_replace($replaced,$replacer,$offset,strlen($replaced));
}