Name

strlen()

Synopsis

    int strlen ( string str )

The strlen() function takes just one parameter (the string), and returns the number of characters in it:

    print strlen("Foo") . "\n"; // 3
    print strlen("Goodbye, Perl!") . "\n"; // 14

Behind the scenes, strlen() actually counts the number of bytes in your string, as opposed to the number of characters. It is for this reason that multibyte strings should be measured with mb_strlen().

Get PHP in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.