How To Remove a Char from a String in Laravel
In this lesson, we are going to see how to remove a char from a string in Laravel, the remove helper method is used to remove one or many characters from any given string.
The Str::remove helper method
The remove() method removes one or many characters from any given string.
use Illuminate\Support\Str;
$hello = Str::remove('?', 'Hello?');
echo $hello;
// Returns "Hello"
The Str::remove helper method is case sensitive
You can disable the case-sensitive removal by using the code below:
use Illuminate\Support\Str;
$hello = Str::remove('L', 'Hello', false);
echo $hello;
// Returns "Heo"