php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #61626 %c format code ignores width specification
Submitted: 2012-04-04 18:20 UTC Modified: 2013-10-09 06:16 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: donretzlaff at gmail dot com Assigned: krakjoe (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.3.10 OS: Ubuntu
Private report: No CVE-ID: None
 [2012-04-04 18:20 UTC] donretzlaff at gmail dot com
Description:
------------
Nothing unique about my configuration; I've tried this on several different
machines with different PHP versions and received the same result.

When I attempt to use the %c formatting code with (for example, sprintf()),
it ignores any width specifier that I indicate, as in the example code below.

I saw nothing in the documentation that the %c code would not react to a width
specifier any differently than the other data formats.

Test script:
---------------
<pre>
<?php 

$x = ord('A');

echo sprintf("|%c|\n",$x);
echo sprintf("|%1c|\n",$x);
echo sprintf("|%2c|\n",$x);
echo sprintf("|%3c|\n",$x);
echo sprintf("|%4c|\n",$x);
echo sprintf("|%5c|\n",$x);
echo sprintf("|%6c|\n",$x);
echo sprintf("|%7c|\n",$x);
echo sprintf("|%-8c|\n\n\n",$x);

?>

Expected result:
----------------
|A|
|A|
| A|
|  A|
|   A|
|    A|
|     A|
|      A|
|A       |


(I expected this because this is what the equivalent code in C produces)

Actual result:
--------------
|A|
|A|
|A|
|A|
|A|
|A|
|A|
|A|
|A|

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-30 19:28 UTC] mike@php.net
-Type: Bug +Type: Documentation Problem -Package: Output Control +Package: Documentation problem
 [2013-10-09 06:16 UTC] krakjoe@php.net
Automatic comment from SVN on behalf of krakjoe
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=331738
Log: #61626 include warning about %c ignoring width/padding
 [2013-10-09 06:16 UTC] krakjoe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: krakjoe
 [2013-10-09 06:16 UTC] krakjoe@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 14 14:01:31 2025 UTC