Laravel Check If String Starts with Specific Value Example
Hi Folks,
In this post, we will learn how to check if string starts with specific character in laravel. It's a simple example of laravel string starts with. I would like to share with you laravel str starts with. we will help you to give an example of laravel Str::startsWith example.
The Str::startsWith() method in Laravel is used to check if a string starts with a specified value.
The Str::startsWith() method takes two parameters: the string to search and the value to check if it starts with. It returns true if the string starts with the specified value(s), otherwise it returns false.
let's see the simple example:
Laravel String Starts With in Controller
you can use it with controller like this way:
Controller Code:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
class UserController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$string = "Hello, Hardik";
$result = Str::startsWith($string, 'Hello');
dd($result);
}
}
Output:
true
Laravel String Starts With in Blade File
you can use it with blade file like this way:
Blade File Code:
<p>{{ Str::startsWith("Hello, Hardik", 'hello') }}</p>
Output:
false
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Get Length of String in Laravel?
- Laravel Convert String to Uppercase Example
- Laravel Convert String to Lowercase Example
- Laravel Import Large CSV File Using Queue Example
- How to Replace String in Laravel?
- How to Install and Setup Supervisor in Ubuntu for Laravel?
- Laravel String Contains Case Insensitive Example
- Laravel Stripe Checkout Payment Integration Example
- How to Convert String to Array Conversion in Laravel?
- How to Install and Use Laravel Debugbar?
- Laravel PayPal Send Payment to Email Example
- Laravel Delete All Records Older Than 7 Days Example
- Laravel Instagram API Tutorial Example