php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28348 str_pad counts unicode characters as two
Submitted: 2004-05-10 13:19 UTC Modified: 2004-05-10 15:54 UTC
From: shy at weblab dot pt Assigned:
Status: Not a bug Package: Output Control
PHP Version: 4.3.4 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: shy at weblab dot pt
New email:
PHP Version: OS:

 

 [2004-05-10 13:19 UTC] shy at weblab dot pt
Description:
------------
In a utf-8 encoded page str_pad counts 8-bit characters 
as two.

Reproduce code:
---------------
<?=str_pad('Na??o',10,'.'),'Representante';?>

Expected result:
----------------
Na??o.....Representante

Actual result:
--------------
Na??o...Representante

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-05-10 15:54 UTC] amt@php.net
In general, PHP is not Unicode savvy. You should use 
something like mb_strlen() to discover the length of 
your string and do the math yourself to create the 
correctly padded string. i.e.

str_repeat('.', max(0, 10 - mb_strlen('Nao')));
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu May 19 19:04:05 2022 UTC