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
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: 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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC