strlen – PHP String Functions

Syntax :

int strlen ( string );

Description :

It’s an inbuilt function of PHP. The strlen() function returns the length of a string.


Parameter :

[table caption=”” width=”100%” colwidth=”15%|15%|15%|55%” colalign=”left|left|left|left”]
Name, Required /Optional, Value Type, Description

string, Required, String, String to check the length.

[/table]


Output :

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


ChangeLog :

[table caption=”” width=”100%” colwidth=”25%|75%” colalign=”left|left”]
PHP Version, Description
5.3.0, Prior versions treated arrays as the string Array thus returning a string length of 5 and emitting an E_NOTICE level error.

[/table]


Related articles : substr_count(), str_word_count().


strlen() – PHP Functions Example 1 : Return the length of the string
<?php
echo strlen("Hi from tutorialmines.");
?>

Output of above code in the browser is as below:

22

strlen() – PHP Functions Example 2 : Returns 0 if the string is empty.
<?php
echo strlen("");
?>

Output of above code in the browser is as below:

0

You may also like...