ItSolutionStuff.com

Laravel Check If String Starts with Specific Value Example

By Hardik Savani • November 5, 2023
Laravel

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...

Tags: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Get Length of String in Laravel?

Read Now →

Laravel Convert String to Uppercase Example

Read Now →

Laravel Convert String to Lowercase Example

Read Now →

Laravel Import Large CSV File Using Queue Example

Read Now →

How to Replace String in Laravel?

Read Now →

How to Install and Setup Supervisor in Ubuntu for Laravel?

Read Now →

Laravel String Contains Case Insensitive Example

Read Now →

Laravel Stripe Checkout Payment Integration Example

Read Now →

How to Convert String to Array Conversion in Laravel?

Read Now →

How to Install and Use Laravel Debugbar?

Read Now →

Laravel PayPal Send Payment to Email Example

Read Now →

Laravel Delete All Records Older Than 7 Days Example

Read Now →

Laravel Instagram API Tutorial Example

Read Now →