Replace the first occurrence of $search in $subject with $replace.

@param  string  $search
@param  string  $replace
@param  string  $subject
@param  string  $encoding
@param  int     &$offset

@return string
496811
protected function replaceLastOne($search, $replace, $subject, $encoding, &$count, &$offset = null, $lenSearch = null)
	{
		$target = mb_substr($subject, 0, $offset, $encoding);
		$position = mb_strrpos($target, $search, 0, $encoding);

		if ($position === false){
			$offset = false;
			return $subject;
		}

		$lenSearch = is_null($lenSearch) ? mb_strlen($search, $encoding) : $lenSearch;

		$start = mb_substr($subject, 0, $position, $encoding);
		$end = $replace.mb_substr($subject, $position+$lenSearch, null, $encoding);

		$offset = -mb_strlen($end, $encoding);
		++$count;

		return $start.$end;
	}
1055057
public function replace($search, $replace): NamespaceDeclaration
    {
        $this->docComment->replace($search, $replace);
        $this->elements->replace($search, $replace);

        return $this;
    }
55311
public function replaceFirst( string $search, string $replace ) : SplString
    {
        if( $search == '' ){
            return $this;
        }

        $position = strpos( $this->__toString(), $search );

        if( $position !== false ){
            return $this->setString( substr_replace( $this->__toString(), $replace, $position, strlen( $search ) ) );
        }

        return $this;
    }
848396
private function replaceMatches($type, $pattern, $subject, $responseBody)
    {
        $matches = [];

        $matchCount = preg_match_all(
            $pattern,
            $subject,
            $matches
        );

        if ($matchCount > 0) {
            // we don't need full matches
            unset($matches[0]);
            $responseBody = $this->replaceMatchesInBody($matches, $type, $responseBody);
        }

        return $responseBody;
    }
12619
protected function strReplaceOnce(string $search, string $replace, string $subject): string
    {
        $pos = strpos($subject, $search);
        if ($pos === false) {
            return $subject;
        }

        return substr($subject, 0, $pos) . $replace . substr($subject, $pos + strlen($search));
    }
280636
public static function replace(string $subject, $pattern, $replacement = null, int $limit = -1): string
    {
        if (\is_object($replacement) || \is_array($replacement)) {
            if (!\is_callable($replacement, false, $textual)) {
                throw new RegexpException("Callback '$textual' is not callable.");
            }

            return static::pcre('preg_replace_callback', [$pattern, $replacement, $subject, $limit]);

        }

        if ($replacement === null && \is_array($pattern)) {
            $replacement = \array_values($pattern);
            $pattern = \array_keys($pattern);
        }

        return static::pcre('\preg_replace', [$pattern, $replacement, $subject, $limit]);
    }
34292
public function replace(string $search, string $replacement): self
    {
        if (!$this->contains($search)) {
            return $this;
        }

        return $this
            ->split($search)
            ->join($replacement);
    }
716721
public function swapTablePrefix($search, $replace)
    {
        $Sql = empty($this->sqlFinalStatement) ? $this->sqlStatement : $this->sqlFinalStatement;

        $this->sqlFinalStatement = preg_replace('/(\W)' . $search . '(\S+?)/', '\\1' . $replace . '\\2', $Sql);

        return $this;
    }
477531
public static function ucpPregReplace($pattern, $replace, $subject, $callback = false)
    {
        if ($callback) {
            $replaced = preg_replace_callback(
                $pattern,
                create_function('$matches', 'return ' . $replace . ';'),
                $subject
            );
        } else {
            $replaced = preg_replace($pattern, $replace, $subject);
        }

        // If preg_replace() returns false, this probably means unicode support is not built-in,
        // so we need to modify the pattern a little
        if ($replaced === false) {
            if (is_array($pattern)) {
                foreach ($pattern as $cur_key => $cur_pattern) {
                    $pattern[$cur_key] = str_replace('\p{L}\p{N}', '\w', $cur_pattern);
                }

                $replaced = preg_replace($pattern, $replace, $subject);
            } else {
                $replaced = preg_replace(str_replace('\p{L}\p{N}', '\w', $pattern), $replace, $subject);
            }
        }

        return $replaced;
    }
401143
public static function last_replace($search, $replace, $string)
    {
        $pos = strrpos($string, $search);
        
        if($pos !== false)
        {
            return substr_replace($string, $replace, $pos, strlen($search));
        }
        else
        {
            return $string;
        }
    }
1159456
protected function strReplace($search, $replace, $subject)
    {
        $template = $this->getTemplateVariable($search);

        return str_replace($template, $replace, $subject);
    }
1171044
public function replaceText($search, $replace)
    {
        if (!$this->open('r+')) {
            return false;
        }

        if ($this->lock !== null && flock($this->handle, LOCK_EX) === false) {
            return false;
        }

        $replaced = $this->write(str_replace($search, $replace, $this->read()), 'w', true);

        if ($this->lock !== null) {
            flock($this->handle, LOCK_UN);
        }
        $this->close();

        return $replaced;
    }
1367717
public function substrReplace($replace, $start, $offset = null)
    {
        return $this->cloneInstance(
            function (StringObject $new) use ($replace, $start, $offset) {
                $new->string = Mbstring::substrReplace($new->string, $replace, $start, $offset, $this->encoding);
            }
        );
    }
1299427
public function replace($search, $replace): FileDeclaration
    {
        $this->docComment->replace($search, $replace);
        $this->elements->replace($search, $replace);

        return $this;
    }
1123614
public function replace($pattern, $replacement , $subject, $limit = -1, &$count = null)
    {
        return $this->sandbox->run('preg_replace', func_get_args(), $this->throw);
    }
1358765
public function replaceLast( string $search, string $replace ) : SplString
    {
        $position = strrpos( $this->__toString(), $search );

        if( $position !== false ){
            return $this->setString( substr_replace( $this->__toString(), $replace, $position, strlen( $search ) ) );
        }

        return $this;
    }
866442
private function replace(
        ColumnMetadata $columnMetadata,
        string $searchTerm,
        string $replaceTerm,
        string $subject
    ): FieldReplaceResult {
        $fieldReplaced = null;
        foreach ($this->replacementStrategyList as $replacementStrategy) {
            if ($replacementStrategy->canReplace($searchTerm, $subject)) {
                $fieldReplaced = $replacementStrategy->replace(
                    $columnMetadata,
                    $searchTerm,
                    $replaceTerm,
                    $subject
                );
                break;
            }
        }

        if (is_null($fieldReplaced)) {
            throw new \RuntimeException('Error trying to replace "' . $searchTerm . '" with "' . $replaceTerm . '"');
        }

        return $fieldReplaced;
    }