Logo

Programming-Idioms

History of Idiom 169 > diff from v44 to v45

Edit summary for version 45 by ricardo_sdl:
[PHP] It was returning the number of bytes and the length of the string

Version 44

2018-08-22, 17:20:23

Version 45

2018-08-22, 17:29:32

Idiom #169 String length

Assign to integer n the number of characters of string s.

This can be different from the number of bytes of s.

Illustration

Idiom #169 String length

Assign to integer n the number of characters of string s.

This can be different from the number of bytes of s.

Illustration
Extra Keywords
size
Extra Keywords
size
Code
$n = strlen($s);
Code
$n = mb_strlen($s, 'UTF-8');
Comments bubble
returns the number of bytes (good for ascii strings as 1 byte = 1 character)
Comments bubble
returns the number of characters in the UTF-8 string s
Doc URL
https://secure.php.net/manual/en/function.strlen.php
Doc URL
https://secure.php.net/manual/en/function.mb-strlen.php
Demo URL
https://3v4l.org/vB4JM
Demo URL
https://3v4l.org/LGHWj