How to Get Part of a String before Another String or Character in Laravel
In this lesson, we are going to see how to get part of a string before another string or character in Laravel, the before helper method is used to return part of a string before the first occurrence of a given string.
The Str::before helper method
The before() method is used to return a section of a string before the first occurrence of a specific string.
use Illuminate\Support\Str;
$website = 'http://www.website.com?id=1';
$website = Str::before($website, '?');
echo $website;
// Returns "http://www.website.com"