php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #45676 The documentation for strlen() is inaccurate
Submitted: 2008-08-01 14:52 UTC Modified: 2008-08-04 12:48 UTC
From: mtesta at money-media dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: Irrelevant OS: Windows XP
Private report: No CVE-ID: None
 [2008-08-01 14:52 UTC] mtesta at money-media dot com
Description:
------------
The documentation for strlen() is inaccurate. From my tests it looks like strlen() returns the number of bytes in a string, not the number of characters.

Reproduce code:
---------------
$str = '?';

echo 'strlen(€) when € is encoded in ANSI (only one byte long): ' . strlen(mb_convert_encoding($str, 'WINDOWS-1252'));
echo ' - strlen(€) when € is encoded in UTF-8 (two bytes long): ' . strlen(mb_convert_encoding($str, 'UTF-8'));

Expected result:
----------------
strlen(?) when ? is encoded in ANSI (only one byte long): 1 - strlen(?) when ? is encoded in UTF-8 (only two bytes long): 1

Actual result:
--------------
strlen(?) when ? is encoded in ANSI (only one byte long): 1 - strlen(?) when ? is encoded in UTF-8 (only two bytes long): 2

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-04 12:48 UTC] rquadling@php.net
Currently the documentation doesn't reflect the changes coming in PHP6 with regard to unicode strings. In V5 and lower, all strings should be considered as binary.

Again, there is a user note covering a strlen function for unicode strings.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 13:01:32 2024 UTC