Laravel 5 String Helpers: Replacing the First Occurrence of a Value

The replaceFirst helper method is used to replace the first occurrence of a given $search string with the provided $replace string in the $subject string. All three parameters are required and must be strings.

Signature

The signature of the replaceMethod is:

{language=php}

public static function replaceFirst(
$search,
$replace,
$subject
);

Example Use

The following examples highlight the basic usage of the replaceFirst method. The results of the method call will appear above the call as a comment.