php replace first occurrence in string

Solutions on MaxInterview for php replace first occurrence in string by the best coders in the world

showing results for - "php replace first occurrence in string"
Silvia
05 Aug 2020
1$pos = strpos($haystack, $needle);
2if ($pos !== false) {
3    $newstring = substr_replace($haystack, $replace, $pos, strlen($needle));
4}
similar questions
queries leading to this page
php replace first occurrence in string