Answers for "how do i replace just the first occurance of a character in a string in php"

PHP
3

php replace every occurrence of character in string

//replaces every occurence of $search with $replace in the string $subject
str_replace ($search, $replace, $subject);
Posted by: Guest on July-12-2020
0

php replace first occurrence in string

$pos = strpos($haystack, $needle);
if ($pos !== false) {
    $newstring = substr_replace($haystack, $replace, $pos, strlen($needle));
}
Posted by: Guest on October-04-2021

Code answers related to "how do i replace just the first occurance of a character in a string in php"

Browse Popular Code Answers by Language