String and text manipulation
The string manipulation functions are found in the Illuminate\Support
namespace and are callable on the Str
object.
Most of the functions also have shorter snake_case
aliases. For example, the Str::endsWith()
method is identical to the global ends_with()
function. We are free to use whichever one we prefer in our application.
Boolean functions
The following functions return the true
or false
values:
- The
is
method checks whether a value matches a pattern. The asterisk can be used as a wildcard character as shown here:Str::is('projects/*', 'projects/php/'); // Returns true
- The
contains
method, as shown in the following code, checks whether a string contains a given substring:Str::contains('Getting Started With Laravel', 'Python'); ...
Get Laravel 5 Essentials now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.