src/String/StringTools.php
public static function replaceFirst($search, $replace, $subject, $caseSensitive = true)
    {
        if ($caseSensitive) {
            $pos = strpos($subject, $search);
        } else {
            $pos = stripos($subject, $search);
        }
        if ($pos !== false) {
            return substr_replace($subject, $replace, $pos, strlen($search));
        }
        return $subject;
    }
public static function replaceFirst($search, $replace, $subject, $caseSensitive = true)
    {
        if ($caseSensitive) {
            $pos = strpos($subject, $search);
        } else {
            $pos = stripos($subject, $search);
        }
        if ($pos !== false) {
            return substr_replace($subject, $replace, $pos, strlen($search));
        }
        return $subject;
    }
public static function replaceFirst ( $ search , $ replace , $ subject , $ caseSensitive = true ) { if ( $ caseSensitive ) { $ pos = strpos ( $ subject , $ search ) ; } else { $ pos = stripos ( $ subject , $ search ) ; } if ( $ pos !== false ) { return substr_replace ( $ subject , $ replace , $ pos , strlen ( $ search ) ) ; } return $ subject ; }
Replaces only the first matched instance of a string

@param string $search
@param string $replace
@param string $subject
@param bool $caseSensitive
@return mixed
Replaces only the first matched instance of a string