How To Use Strlen Function With Examples Using PHP

admin_img Posted By Bajarangi soft , Posted On 24-09-2020

The strlen() function return the length of the input string.

PHP strlen Function with an example

Syntax of strlen() function and Usage:

strlen(string)


Parameter Values
string -> The fucntion returns the length of the input string including all the whitespaces and special characters.

Let's learn

1.Create string.
$string="BAJARANGISOFT";


2.Print string using strlen() function.
echo strlen($string);

 
Example(1)
<?php
$string="BAJARANGISOFT";
echo "<h4>".strlen($string). "</h4>";
echo "<h4>".strlen("BAJARANGISOFT"). "</h4>";
?>


Complete Code of strlen() Function:
<!DOCTYPE html>
<html lang="en">
<head>
    <title>PHP string length function</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>
<body>
<div class="container">
    <div class="text-center">
        <h1>PHP strlen() Function</h1>
    </div>
    <br>
    <h2>The strlen() function return the length of the input string.</h2>
    <div class="well">
        <?php
        $string="BAJARANGISOFT";
        echo "<h4>".strlen($string). "</h4>";
        echo "<h4>".strlen("BAJARANGISOFT"). "</h4>";
        ?>
    </div>
    <br>
</div>
</body>
</html>

Related Post