Find String length using PHP


Solutions Find String length using PHP String Count PHP

To find the string length using PHP we will use the PHP function strlen() . The function of PHP strlen() will count the number of characters in the string or total count and return the length value of the string.

Syntax of PHP function strlen()

The function strlen() only accept the one parameter that contain the string or strings values.

<?php strlen(String_Parameter); //Syntax strlen('Hello'); //Example ?>

Program to calculate the length of the string using PHP

Now we are going to calculate the length of the string and sentence using PHP and will print the lenght.

<?php $string1 = "Hello"; echo "String 1 Length : ".strlen($string1); echo "<br>"; $string2 = "Hello World !"; echo "String 2 Length : ".strlen($string2); ?>

Output

String 1 Length : 5 String 2 Length : 13
Solutions String Count PHP Chapter Next »