w3resource

PHP: strlen() function

PHP: Get string length

The strlen() function is used to return the length of a string.

Version:

(PHP 4 and above)

Syntax:

strlen(string_name)

Parameter:

Name Description Required /
Optional
Type
string_name The specified string. Required String

Return value:

The length of the string on success, and 0 for an empty string.

Value Type: Integer.

Example:

<?php 
$string_name = 'Welcome to w3resource.com';
echo strlen($string_name)."<br>";
$string_name = ' Welcome to w3resource.com  ';
echo strlen($string_name)."<br>";
?>

Output:

25
28

View the example in the browser

See also

PHP Function Reference

Previous: stripos
Next: strnatcmp



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/php/function-reference/strlen.php