php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63928 unexpected behaviour of sprintf
Submitted: 2013-01-07 09:19 UTC Modified: 2013-01-07 10:27 UTC
From: Mikayuoads at gmail dot com Assigned:
Status: Wont fix Package: Unknown/Other Function
PHP Version: 5.4.10 OS: Gentoo
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: Mikayuoads at gmail dot com
New email:
PHP Version: OS:

 

 [2013-01-07 09:19 UTC] Mikayuoads at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.sprintf#refsect1-function.sprintf-seealso
---

Right padding doesn't work with zeros.

Test script:
---------------
echo sprintf('%\'0-5d', 42); // output: '42   '
echo sprintf('%0-5d', 42); // output: '42   '
echo sprintf('%\'#-5d', 42); // output: '42###'

Expected result:
----------------
expected result:
echo sprintf('%\'0-5d', 42); // output: '42000'
echo sprintf('%0-5d', 42); // output: '42000'
echo sprintf('%\'#-5d', 42); // output: '42###'


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-07 10:27 UTC] cataphract@php.net
-Status: Open +Status: Wont fix
 [2013-01-07 10:27 UTC] cataphract@php.net
The sprintf() function specified for the C standard, and upon which PHP's function is based explicitly says that "[i]f the 0 and-flags both appear, the 0 flag is ignored."

Implementing different behavior in PHP would be ill-advised.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 13:01:28 2024 UTC