Write a PHP program to find the length of the string
Description: Write a PHP program to find the length of a string.
Rules and hints:
- Use one variable.
- Use a built-in PHP string function.
PHP program to find the length of a string
<?php
$str = "Tutorials Class";
echo strlen($str);
?>
Output:
Tutorials Class - Output Window
15
How it works
strlen()returns the number of characters (bytes) of the string.- The space between the two words is counted too, so the length is 15.
For non-English text read strlen() vs mb_strlen().
Learn more about the similar topics:
| Tutorials |
|---|
| PHP String Handling |
| PHP explode() Function |
| PHP strpos() Function |
| PHP implode() Function |