replace only first occurrence of string in php code example Example: replace all occurrence char in string php $string = str_replace('search','replace',$string);