PHP strlen() string function



The PHP strlen() function returns the string length, means count of character string contain.

Here we take an example of count character of given string using strlen() function.

PHP strlen() function syntax

strlen(“string”);

PHP strlen() function example

<?php
echo "The length of string = " . strlen("Meera Academy");
?>

The output of above strlen() function example is:

The length of string = 13

Now, lets more understand about php strlen() function with php example.

In this php example we enter value in textbox and calculated length of entered text using php strlen() function in php form.

PHP example of strlen() function

create php form with name firstexample.php look like  :

<html>
<head>
<title>PHP strlen() Function</title>
</head>
<body>

<FORM method="POST" action="firstexample.php">

Name : <input type="text" name="name"></br></br>
<input type="submit" name="Submit1" value="String Length">

</FORM>

<?php
if(isset($_POST['Submit1']))
{
echo "The Length of string = ". strlen($_POST["name"]);
}
?>

</body>
</html>

The above php strlen() function example out put is:

PHP strlen() string function
PHP strlen() string function

Here, above example when we enter “Meera Academy” text in textbox then the out put is length= 13 and for “jay” the length=3.

Next php tutorial we will learn php substr() function.

Leave a Reply

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