PHP替换字符串(只替换首个字符串)
时间:2021-07-01 10:21:17
帮助过:34人阅读
- $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;
|