w3resource

PHP: strlen() function

Description

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



PHP: Tips of the Day

PHP: PHPDoc type hinting for array of objects?

Use:

/* @var $objs Test[] */
foreach ($objs as $obj) {
    // Typehinting will occur after typing $obj->
}

when typehinting inline variables, and

class A {
    /** @var Test[] */
    private $items;
}

Ref : https://bit.ly/31a2QJN