php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #81244 make *printf() function Unicode-aware
Submitted: 2021-07-11 10:21 UTC Modified: 2021-07-12 13:31 UTC
From: flightvision at googlemail dot com Assigned:
Status: Wont fix Package: *Unicode Issues
PHP Version: 8.0.8 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: flightvision at googlemail dot com
New email:
PHP Version: OS:

 

 [2021-07-11 10:21 UTC] flightvision at googlemail dot com
Description:
------------
The *printf() functions are having problems if strings contain non-ASCII characters.

Test script:
---------------
echo sprintf('%3.3s', 'ö12345');
echo sprintf('%3.3s', '12ö345');

Expected result:
----------------
ö12
12ö

Actual result:
--------------
ö1
12�

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-12 13:31 UTC] nikic@php.net
-Status: Open +Status: Wont fix
 [2021-07-12 13:31 UTC] nikic@php.net
printf() widths are in terms of bytes, and this isn't going to change. Please use mb_substr() or grapheme_substr() to truncate a string to a certain number of characters, depending on which notion of "character" you wish to use (I would recommend extended grapheme clusters, if you don't want to "truncate" away combining characters etc).
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Oct 28 16:03:36 2021 UTC