English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP strlen() Function Usage and Example

PHP String Character String Function Manual

    The strlen() function is used to return the length of a string, and the handling of Chinese character strings uses mb_strlen() Function

int strlen ( string $string )

Definition and Usage

It is used to get the length of the string.

Return Value

 Returns the length of the string string if successful; if string is empty, returns 0.

Parameter

Serial NumberParameters and Description
1

string

Required. The string that needs to be calculated for length.

Online Example

Try the following example to calculate the length of a string:

<?php
//Calculate the length of a string
$input = 'sairam'12345'; 
echo strlen($input);
echo '<br>';
//Calculate the length of a string containing spaces
$str = '  ab  cd  ';
echo strlen($str); 
echo '<br>';
//Calculate the length of a string containing special characters or punctuation marks
$str = '@abcd$#';
echo strlen($str); 
?>
Test and see‹/›

Output Result

11
7
7

PHP String Character String Function Manual