Getting the length of a string
This example shows how you can get the length of a string , this uses the function strlen() . The format of strlen is strlen(string); . This returns the length of a string as an integer .
In the example below we have 2 strings , the reason behind this is to show that when we measure the length of a string we also measure all of the string not only the characters but the whitespace also.
Code :
<?php
//display length of string(s)
$string1 = "beginners php";
$string2 = "myscripting";
//store the length of the strings in variables
$length1 = strlen($string1);
$length2 = strlen($string2);
//display the length of the strings
echo "String1 has $length1 characters";
echo "String2 has $length2 characters";
?>
Example :
string1 has 13 characters
string2 has 11 characters