In this program, we are finding the length of the string entered by the user. To do so we are using the built-in function strlen()
. For this, we first have to read the string into the variable str and then we have to call the function strlen() with the variable str as the argument and assign it to the variable len. And at last print, the value of the variable len as the number of characters in the string entered.
Syntax of function strlen()
strlen(string)
Step 1: Accept the string from the user and assign it to the variable str
Step 2: To find the length of the string use the built-in function strlen() and the variable str as the argument and assign the result to the variable len
Step 3: Print the value of the variable len as the number of characters in the string entered
<?php
$str = readline("Enter the string: ");
$len = strlen($str);
echo "Number of charachters in $str is : $len";
?>
Enter the string: learnetutorials.com Number of characters in learnetutorials.com is: 19