The strlen()
string function can be used to get the length of a string or the count of characters of a string.
Syntax
$result = strlen($string);
$result
The length of $string
as integer data type. See examples below.
$string
Required parameter as string data type.
Examples
Code snippets in examples below have been tested in PHP parser version 5.3.29.
Examples show how the number of characters of a given string can be returned using the strlen()
string function.
strlen() function | $result |
---|---|
strlen("MyString") | 8 |
strlen("Open seven days a week.") | 23 |
strlen("Open 7 days a week.") | 19 |
strlen("A") | 1 |
strlen() | NULL |
strlen("") | 0 |
strlen(4) | 11) |
strlen("0123") | 41) |
strlen(array("A", "B", "C")) | NULL2) |
1) Integer values are not defined but work in this example.
2) In PHP 5.3.x, the function will return NULL when passing incompatible parameters.