By 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.
#Signature
The signature of the start
method is:
1public static function start(
2 $value,
3 $prefix
4 );
#Example Use
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);
#Global str_start
Helper Function
The str_start
function is a shortcut to calling Str::start
. This function is defined in the global namespace.
∎