Member Login:


PHP: Get The Length Of A String

Document Reference: TN200908007 - Rev: 4.2 - Last Update: 02-07-2016 08:54 GMT - Downloaded: 26-Mar-2019 13:59 GMT

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.

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