src/Strings.php
/**
   * Replace the first instance of a string in another string,
   * if it exists.
   *
   * @param string $search        The string being to be replaced.
   * @param string $replace       The string to replace $search with.
   * @param string $subject       The string that is being searched for $search.
   * @return string               If $search doesn't exist, this returns $subject unmodified.
   */
Replace the first instance of a string in another string,
if it exists.

@param string $search        The string being to be replaced.
@param string $replace       The string to replace $search with.
@param string $subject       The string that is being searched for $search.
@return string               If $search doesn't exist, this returns $subject unmodified.
Replace the first instance of a string in another string if it exists . @param string $search The string being to be replaced . @param string $replace The string to replace $search with . @param string $subject The string that is being searched for $search . @return string If $search doesn ' t exist this returns $subject unmodified .
public static function replaceFirst(string $search, string $replace, string $subject)
    {
        $pos = strpos($subject, $search);
        if ($pos !== false) {
            return substr_replace($subject, $replace, $pos, strlen($search));
        }
        return $subject;
    }
public static function replaceFirst ( string $ search , string $ replace , string $ subject ) { $ pos = strpos ( $ subject , $ search ) ; if ( $ pos !== false ) { return substr_replace ( $ subject , $ replace , $ pos , strlen ( $ search ) ) ; } return $ subject ; }
Replace the first instance of a string in another string,
 if it exists.
Replace the first instance of a string in another string if it exists .