$str=preg_replace('/abc/','xyz',$str,1); echo $str; 复制代码 不用正则的字符串替换代码: $replace='xyz'; if(($position=strpos($str,$replace))!==false){ $leng=strlen($replace); $str=substr_replace($str,'xyz',$position,$leng); } echo $str; 复制代码