strlen() Function – PHP/LARAVEL With Code Example

how to find string length in php laravel
In this article, we will learn what is strlen() function is in PHP and Laravel, and in this article, you have been told with the example that how we can use this function in PHP and Laravel.

It is very easy to find the length of the string in PHP and Laravel. There are functions in Laravel with the help of which the length of the string can be found.

There are other string-length functions that are mentioned in this article.

What is the strlen() function in PHP/Laravel:-

strlen() function is a helper or built-in function in PHP and Laravel. This function is used to get the total length of a string. This function outputs data in an integer value.

#How to find string length in PHP:-

  • strlen() function finds the length of a string.
  • In this method str means string and len means length. Whenever the length of the string is counted in this function, an integer is an output.
Syntex: strlen();

Example :-

    <?php

        $strLength = strlen('what is the length of the string in this line');

        echo "String length is" . ' '. $strLength; die();

    ?>
OUTPUT : –

String length is 45

#How to find string length in Laravel: –
Method1. – strlen(); function – find the length of the string
Method2. – Str::length(); function – find the length of the string
  • It is very easy to find the length of the string in Laravel. There are functions in Laravel with the help of which the length of the string can be found.
  • Whenever the length of a string is factorized, spaces are also considered as a string, and spaces are counted in the length of the string.
  • In this method str means string. Whenever the length of the string is counted in this function, an integer is an output.

Method1:- strlen();

syntex: strlen();

Example : –

    <?php

    namespace App\Http\Controllers;

    use Illuminate\Http\Request;

    use Illuminate\Support\Str;

    class SaveDataController extends Controller

    {

        public function index()

        {

            $strLength = strlen('what is the length of the string in this line');

            echo "<pre>";

            print_r('String length is' . ' ' . $strLength);

            die();

            return view('form');

        }

    }

OUTPUT:-

find string length

Method2:- Str::length();

syntex: Str::length();

Example :-

    <?php

    namespace App\Http\Controllers;

    use Illuminate\Http\Request;

    use Illuminate\Support\Str;

    class SaveDataController extends Controller

    {

        public function index()

        {

            $strLength = Str::length('what is the length of the string in this line');

            echo "<pre>";

            print_r('String length is' . ' ' . $strLength);

            die();

            return view('form');

        }

    }

OUTPUT:-

find string length

  • The way of writing the function is different in both these methods, but both these functions work in the same way. Whenever the length of the string is counted in this function, an integer is output.
  • What is string in Laravel: – If any character and text are used in PHP, then it is considered a string in PHP. In PHP, a series of text or characters is called a string.
  • Same predefined function in Laravel is used when string length has to be searched

Leave a Comment

Your email address will not be published. Required fields are marked *