php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #61532 Apostrophe modifier in *printf is broken
Submitted: 2012-03-27 21:28 UTC Modified: 2015-01-14 14:56 UTC
From: iblue at gmx dot net Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.4.0 OS: GNU/Linux
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: iblue at gmx dot net
New email:
PHP Version: OS:

 

 [2012-03-27 21:28 UTC] iblue at gmx dot net
Description:
------------
When I use the apostrophe (') modifier to select a padding character in printf, 
it behaves buggy, when the padding length itself is prefixed by zeroes.

Test script:
---------------
<?php
echo sprintf("%'.9s\n", "foo");
echo sprintf("%'.09s\n", "foo");

Expected result:
----------------
......foo
......foo


Actual result:
--------------
......foo
000000foo


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-04-12 10:09 UTC] johannes@php.net
The current behaviour seems to be in line with what libc does, both on Linux and Solaris (and gcc and suncc):

$ cat test.c
#include <stdio.h>

void main() {
	printf("%'.09i\n", 123);
}

$ gcc -otest test.c
$ ./test 
000000123
 [2012-04-12 10:13 UTC] johannes@php.net
-Type: Bug +Type: Documentation Problem
 [2012-04-12 10:13 UTC] johannes@php.net
It should be  documented that 0 as padding specifier overwrites a manually set one.
 [2015-01-14 14:55 UTC] danack@php.net
Automatic comment from SVN on behalf of danack
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=335742
Log: Added detail about padding character for bug 61532
 [2015-01-14 14:56 UTC] danack@php.net
-Status: Open +Status: Not a bug
 [2015-01-14 14:56 UTC] danack@php.net
It has been documented that 0 as padding specifier overwrites a manually set one.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 12:01:33 2025 UTC