November 30, 2017 —John Koster
The start
helper method will make sure that a given $value
always begin with exactly one occurrence of the $prefix
. This helper method can be used to help generate absolute URLs from relative path names. The $prefix
can be any string value.
The signature of the start
method is:
1public static function start(2 $value,3 $prefix4 );
1use Illuminate\Support\Str; 2 3// /home/path 4echo Str::start('/home/path/' '/'); 5 6// home/path 7echo Str::start('home/path/', '/'); 8 9// Generate absolute URLs from relative paths.10$domain = 'https://youtube.com';11$channelPath = Str::start('UCb9XEo_1SDNR8Ucpbktrg5A', '/channel/');12 13$absolutePath = Str::start($channelPath, $domain);
str_start
Helper FunctionThe str_start
function is a shortcut to calling Str::start
. This function is defined in the global namespace.
∎
The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.