I want a version of str_replace() that only replaces the first occurrence of $search in the $subject. Is there an easy solution to thi
str_replace()
$search
$subject
function str_replace_once($search, $replace, $subject) { $pos = strpos($subject, $search); if ($pos === false) { return $subject; } return substr($subject, 0, $pos) . $replace . substr($subject, $pos + strlen($search)); }