Member Login:

PHP: Get The Length Of A String

Document Reference: TN200908007 - Rev: 4.2 - Last Update: 02-07-2016 08:54 GMT - Downloaded: 24-Sep-2023 18:06 GMT

The strlen() string function can be used to get the length of a string or the count of characters of a string.


$result = strlen($string);


The length of $string as integer data type. See examples below.


Required parameter as string data type.


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("Open seven days a week.")23
strlen("Open 7 days a week.")19
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.

This website uses cookies to give you the best experience on our website, to personalise content and to analyse our website traffic. Some cookies may have been set already. To find out more about our use of cookies you can visit our Privacy Statement. By browsing this website, you agree to our use of cookies.

Hide this message