PHP replace string (only replace the first string)
WBOYOriginal
2016-07-25 08:52:20960browse
$str=preg_replace('/abc/','xyz',$str,1);
echo $str;
Copy code
Do not use regular string replacement code:
$replace='xyz';
if(($position=strpos($str,$replace))!==false){
$leng=strlen($replace);
$str=substr_replace ($str,'xyz',$position,$leng);
}
echo $str;
Copy code
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn