November 30, 2017 —John Koster
The is
helper method will indicate if the given $value
matches the given $pattern
. If the $value
is the $pattern
or if the $value
matches the $pattern
, the method will return true
, otherwise it returns false
.
The signature of the is
method is:
1public static function is(2 $pattern,3 $value4 );
The following examples will return true
:
1use Illuminate\Support\Str; 2 3// true 4Str::is('word', 'word'); 5 6// true 7Str::is('pre*', 'prepare'); 8 9// true10Str::is('*pare', 'prepare');11 12// true13Str::is('*pare', 'compare'));14 15// true16Str::is('m*e', 'mouse');17 18// true19Str::is('m*e', 'meme');
The following example return false
, and is just to demonstrate that the is
method will not match traditional regular expressions:
1use Illuminate\Support\Str;2 3// false4Str::is('[0-9]', '1');
However, any of these would return true:
1use Illuminate\Support\Str;2 3// true4Str::is('[0-9]*', '[0-9] any thing');5 6// true7Str::is('[0-9]*', '[0-9][a-z]');
str_is
Helper FunctionThe str_is
function is a shortcut to calling Str::is
. This function is declared 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.