The after function returns everything after the given value in a string.
The entire string will be returned if the value does not exist within the string:
after('This is my name', 'This is');
// ' my name'The afterLast function returns everything after the last occurrence of the given value in a string.
The entire string will be returned if the value does not exist within the string:
afterLast('App\\Http\\Controllers\\Controller', '\\');
// 'Controller'The ascii function will attempt to transliterate the string into an ASCII value:
ascii('ü');
// 'u'The before function returns everything before the given value in a string:
before('This is my name', 'my name');
// 'This is 'The beforeLast function returns everything before the last occurrence of the given value in a string:
beforeLast('This is my name', 'is');
// 'This 'The between function returns the portion of a string between two values:
between('This is my name', 'This', 'name');
// ' is my 'The betweenFirst function returns the smallest possible portion of a string between two values:
betweenFirst('[a] bc [d]', '[', ']');
// 'a'The charAt function allows to get a character by index from a multibyte string:
charAt('Hello, world!', 1);
// 'e'The contains function determines if the given string contains the given value. This function is case-sensitive:
contains('This is my name', 'my');
// trueYou may also pass an array of values to determine if the given string contains any of the values in the array:
contains('This is my name', ['my', 'foo']);
// trueThe containsAll function determines if the given string contains all the values in the given array:
containsAll('This is my name', ['my', 'name']);
// trueThe convertCase function converts the given string to given mode:
convertCase('HeLLo WoRLD', MB_CASE_LOWER);
// 'hello world'The endsWith function determines if the given string ends with the given value:
endsWith('This is my name', 'name');
// trueYou may also pass an array of values to determine if the given string ends with any of the values in the array:
endsWith('This is my name', ['name', 'foo']);
// true
endsWith('This is my name', ['this', 'foo']);
// falseThe excerpt function extracts an excerpt from the string that matches the first instance of a phrase within that string:
excerpt('This is my name', 'my', {
radius: 3
});
// '...is my na...'The radius option, which defaults to 100, allows you to define the number of characters that should appear on each side of the truncated string.
In addition, you may use the omission option to change the string that will be prepended and appended to the truncated string:
excerpt('This is my name', 'name', {
radius: 3,
omission: '(...) '
});
// '(...) my name'The explode function splits the string by the given delimiter and returns an array containing each section of the split string:
explode('foo bar baz', ' ');
// ['foo', 'bar', 'baz']The finish function adds a single instance of the given value to a string if it does not already end with that value:
finish('this/string', '/');
// 'this/string/'
finish('this/string/', '/');
// 'this/string/'The headline function will convert strings delimited by casing, hyphens, or underscores into a space delimited string with each word's first letter capitalized:
headline('steve_jobs');
// 'Steve Jobs'
headline('EmailNotificationSent');
// 'Email Notification Sent'The is function determines if a given string matches a given pattern. Asterisks may be used as wildcard values
is('foo*', 'foobar');
// true
is(/baz*/, 'foobar');
// falseThe isAscii function determines if a given string is an ASCII string:
isAscii('Taylor');
// true
isAscii('ü');
// falseThe isJson function determines if a given string is valid JSON:
isJson('[1,2,3]');
// true
isJson('{"first": "John", "last": "Doe"}');
// true
isJson('{first: "John", last: "Doe"}');
// falseThe isUlid function determines if a given string is a valid ULID:
isUlid('01ARZ3NDEKTSV4RRFFQ69G5FAV');
// true
isUlid('Taylor');
// falseThe isUrl function determines if a given string is a valid URL:
isUrl('https://example.com');
// true
isUrl('example');
// falseThe isUuid function determines if a given string is a UUID:
isUuid('5ace9ab9-e9cf-4ec6-a19d-5881212a452c');
// true
isUuid('Taylor');
// falseThe isMatch function will return true if the string matches a given regular expression:
isMatch(/foo (.*)/, 'foo bar');
// true
isMatch(/foo (.*)/, 'laravel');
// falseThe lcfirst function returns the given string with the first character lowercase:
lcfirst('Foo Bar');
// 'foo Bar'The length function returns the length of the given string:
length('Laravel');
// 7The limit function truncates the given string to the specified length:
limit('The quick brown fox jumps over the lazy dog', 20);
// 'The quick brown fox...'You may also pass a third argument to change the string that will be appended to the end of the truncated string:
limit('The quick brown fox jumps over the lazy dog', 20, ' (...)');
// 'The quick brown fox (...)'If you want to keep whole words when truncating a string, you can use the fourth argument. When this argument is true, the string will be truncated to the nearest full word boundary:
limit('The quick brown fox jumps over the lazy dog', 12, '...', true);
// 'The quick...'The lower function converts the given string to lowercase:
lower('LARAVEL');
// 'laravel'The ltrim function trims the left side of the string:
ltrim(' Laravel ');
// 'Laravel '
ltrim('/Laravel/', '/');
// 'Laravel/'The mask function masks a portion of a string with a repeated character, and may be used to obfuscate
segments of strings such as email addresses and phone numbers:
mask('taylor@example.com', '*', 3);
// 'tay***************'If needed, you provide a negative number as the third argument to the mask function, which will instruct the function
to begin masking at the given distance from the end of the string:
mask('taylor@example.com', '*', -15, 3);
// 'tay***@example.com'The match function will return the portion of a string that matches a given regular expression pattern:
match('bar', 'foo bar');
// 'bar'
match(/foo (.*)/, 'foo bar');
// 'bar'The matchAll function will return an array containing the portions of a string that match a given regular expression pattern:
matchAll('bar', 'bar foo bar');
// ['bar', 'bar']If you specify a matching group within the expression, package will return an array of that group's matches:
matchAll(/f(\w*)/, 'bar fun bar fly');
// ['un', 'ly']The padBoth function wraps both sides of a string with another string until the final string reaches the desired length:
padBoth('James', 10, '_');
// '__James___'
padBoth('James', 10);
// ' James 'The padLeft function wraps the left side of a string with another string until the final string reaches the desired length:
padLeft('James', 10, '-=');
// '-=-=-James'
padLeft('James', 10);
// ' James'The padRight function wraps the right side of a string with another string until the final string reaches the desired length:
padRight('James', 10, '-');
// 'James-----'
padRight('James', 10);
// 'James 'The parseCallback function parse to an array a Class@method style callback into class and method:
parseCallback('Class@method');
// ['Class', 'method']The preg_quote function quote regular expression characters:
preg_quote('*RRRING* Hello?');
// '\*RRRING\* Hello\?'The remove function removes the given value or array of values from the string:
remove('quite', 'Arkansas is quite beautiful!');
// 'Arkansas is beautiful!'The repeat function repeats the given value N times:
repeat('a', '5');
// 'aaaaa'The replace function replaces a given string within the string:
replace('6.x', '7.x', 'Laravel 6.x');
// 'Laravel 7.x'The replace function also accepts a caseSensitive argument. By default, the replace function is case-sensitive:
replace('10.X', '11.x', 'Laravel 10.x', false);
// 'Laravel 11.x'The replaceArray function replaces a given value in the string sequentially using an array:
replaceArray('?', ['8:30', '9:00'], 'The event will take place between ? and ?');
// 'The event will take place between 8:30 and 9:00'The replaceEnd function replaces the last occurrence of the given value only if the value appears at the start of the string:
replaceEnd('World', 'Laravel', 'Hello World');
// Hello LaravelThe replaceFirst function replaces the first occurrence of a given value in a string:
replaceFirst('the', 'a', 'the quick brown fox jumps over the lazy dog');
// 'a quick brown fox jumps over the lazy dog'The replaceLast function replaces the last occurrence of a given value in a string:
replaceLast('the', 'a', 'the quick brown fox jumps over the lazy dog');
// 'the quick brown fox jumps over a lazy dog'The replaceStart function replaces the first occurrence of the given value only if the value appears at the start of the string:
replaceStart('Hello', 'Laravel', 'Hello World');
// Laravel WorldYou may also pass false as a third parameter to ignore case when removing strings.
The reverse function reverses the given string:
reverse('Hello World');
// 'dlroW olleH'The rtrim function trims the right side of the given string:
trim(' Laravel ');
// ' Laravel'
rtrim('/Laravel/', '/');
// '/Laravel'The slug function generates a URL friendly "slug" from the given string:
slug('Laravel Framework', '-');
// 'laravel-framework'The squish function removes all extraneous white space from a string, including extraneous white space between words:
squish(' laravel framework ');
// 'laravel framework'The start function adds a single instance of the given value to a string if it does not already start with that value:
start('this/string', '/');
// '/this/string'
start('/this/string', '/');
// '/this/string'The startsWith function determines if the given string begins with the given value:
startsWith('This is my name', 'This');
// trueThe stripTags function strips HTML and PHP tags from the given string:
stripTags('before<br>after');
// 'beforeafter'The substr function returns the portion of string specified by the start and length parameters:
substr('The Laravel Framework', 4, 7);
// 'Laravel'The substrCount function returns the number of occurrences of a given value in the given string:
substrCount('If you like ice cream, you will like snow cones.', 'like');
// 2The substrReplace function replaces text within a portion of a string, starting at the position specified by the second argument
and replacing the number of characters specified by the fourth argument. Passing 0 to the function's fourth argument
will insert the string at the specified position without replacing any of the existing characters in the string:
substrReplace('1300', ':', 2);
// '13':
substrReplace('The Framework', ' Laravel', 3, 0);
// 'The Laravel Framework'The swap function replaces multiple values in the string similar to PHP strtr function:
swap({
'Tacos': 'Burritos',
'great': 'fantastic',
}, 'Tacos are great!');
// 'Burritos are fantastic!'The take function returns a specified number of characters from the beginning of a string:
take('Build something amazing!', 5);
// 'Build'The title function converts the given string to Title Case:
title('a nice title uses the correct case');
// 'A Nice Title Uses The Correct Case'The trim function trims the given string:
trim(' Laravel ');
// 'Laravel'
trim('/Laravel/', '/');
// 'Laravel'The ucfirst function returns the given string with the first character capitalized:
ucfirst('foo bar');
// 'Foo bar'The ucsplit function splits the given string into an array by uppercase characters:
ucsplit('Foo Bar');
// ['Foo', 'Bar']The unwrap function removes the specified strings from the beginning and end of a given string:
unwrap('-Laravel-', '- ');
// 'Laravel'The upper function converts the given string to uppercase:
upper('laravel');
// 'LARAVEL'The wordCount function returns the number of words that a string contains:
wordCount('Hello, world!');
// 2The wordWrap function wraps a string to a given number of characters:
wordWrap('The quick brown fox jumped over the lazy dog', 20, "<br />\n");
/*
The quick brown fox<br />
jumped over the lazy<br />
dog.
*/The words function limits the number of words in a string. If necessary, you may specify an additional string that will be appended to the truncated string:
words('Perfectly balanced, as all things should be.', 3, ' >>>');
// 'Perfectly balanced, as >>>'The wrap function wraps the string with the given strings:
wrap('is', 'This ', ' me!');
// 'This is me!'