Published

Laravel 5.5 String Helper Function: before

Making Sure Strings Start With a Given Value in Laravel - Laravel 5.5 String Helper Method. start

The before method can be used to return a part of a string before the first occurrence of a $search character.

This method can be used to help parse URL query strings, or to quickly find substrings based on a certain character; it is the logical opposite of the after helper method.

Signature

The signature of the before method is:

1public static function before(
2 $subject,
3 $search
4 );

Example Use

The before method can be used like so:

1use Illuminate\Support\Str;
2 
3// Outputs "https://stillat.com"
4echo Str::before('https://stillat.com?ref=newsletter', '?');

Recent articles

Stillat

Covering topics from JavaScript to Laravel, and everything in-between since 2012.

Resources

© Stillat, LLC. All right reserved.
Code highlighting provided by Torchlight