PHP Function Reference

PHP strlen() Function



The PHP strlen() function returns the length of the given string.

Note: This function returns the number of bytes rather than the number of characters in a string.

Syntax

strlen(string)

Parameters

string Required. Specify the string being measured for length.

Return Value

Returns the length of the string on success, and 0 if the string is empty.

Example:

In the example below, strlen() function is used to find out the length of the string.

<?php
$MyString = "Hello World!";
$String_Length = strlen($MyString);

echo "String length = ".$String_Length;
?>

The output of the above code will be:

String length = 12

❮ PHP String Reference