How to Replace Portions of an Existing String in Laravel
In this lesson, we are going to see how to replace portions of an existing string in Laravel, the substrReplace helper method is used to replace text in an existing string at a specific location.
The Str::substrReplace helper method
The substrReplace() method is used to replace text within a portion of a given string, the third argument specifies the position, and the fourth is the number of characters to replace.
use Illuminate\Support\Str;
$portion = Str::substrReplace('Darija Coding', '_', 6, 1);
echo $portion;
// Returns "Darija_Coding"