PHP Tutorial PHP Advanced PHP Resources
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

PHP - String strlen() Function



The PHP String strlen() function returns the total number of characters in the specified string. Apart from Alphabets, any symbol, space, special character or number in the string is also considered as a character while finding out the length of the string.

Syntax

strlen(string)

Parameters

string Required. Specify the string to find out total number of characters in it

Return Value

Returns the total number of characters in the specified string.

Example:

In the example below, strlen() function returns the total number of characters in the string called MyString.

<?php
$MyString = "hello world!";
$String_Length = strlen($MyString);

echo $String_Length."\n";
?>

The output of the above code will be:

12

❮ PHP String functions

5