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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mtesta at money-media dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 09 11:01:34 2025 UTC