Laravel 10 Check If String Starts with Specific Value Example
Hello Artisan, today I'll show you how to check if the string starts with a specific character in Laravel in our Laravel application. I'd like to demonstrate the usage of the Laravel Str::startsWith method with a simple example. The Str::startsWith() method in Laravel is used to check if a string starts with a specified value. The Str::startsWith() method, when given a string to search and a value to check for at the beginning, returns true if the string commences with the provided value(s); otherwise, it returns false.
let's see a simple example:
- Install Laravel App
- Laravel String Starts Within Controller
- Output
- Laravel String Starts Within Blade File
- Output
Creating the Laravel app is not necessary for this step, but if you haven't done it yet, you can proceed by executing the following command.
We can use it with a controller this way:
When you visit the URL or route associated with the index method of this controller in your Laravel application, it will execute this code. If the string $string starts with 'Hello', it will display true, otherwise, it will display false.
You can use it with a blade file this way:
That's it for today. I hope it'll be helpful in an upcoming project. Thanks for reading. 🙂
0 Comments
CAN FEEDBACK
Emoji