|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31051 printf() occasional extraneous characters
Submitted: 2004-12-10 08:31 UTC Modified: 2004-12-10 18:33 UTC
From: michael at fishnet dot us Assigned:
Status: Not a bug Package: Output Control
PHP Version: 4.3.10RC2 OS: linux 2.4.20
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
18 + 37 = ?
Subscribe to this entry?

 [2004-12-10 08:31 UTC] michael at fishnet dot us
printf() occasionally returns unexpected trailing characters.  The problem can be difficult to reproduce, as it only rarely happens.  The example URL below does show the problem.  I have never isolated just what causes the format problem, though so far the extraneous characters seem to only occur in floating point formats.  Others have reported the same random behaviour on the FishCart ( support list, from which the example code below is derived.

In the example URL below there is a link to view the exact PH P source that prints the page; this should allow testing the script on other servers and other versions.  This server is running on 4.3.10RC2; it also happened on 4.3.10RC1, 4.3.9 and is also reproducable on a different server running 5.0.2.

Reproduce code:

Expected result:
A few integer and floating point numbers are displayed that should show both integers and floating point numbers formatted to 2 decimal places.

Actual result:
When displaying 42, the printed result is 42.009.  When printing 39 with 0 to 3 trailing spaces in the format string, an ascending count is displayed as follows; the increasing appended number (9, 10, 11, 12) seems to be the overall displayed string length including the $.

$ 39.009
$ 39.00 10
$ 39.00  11
$ 39.00   12

See the script source code in the URL above to see exactly what code is being run.  In particular, look at the page source in the browser to see how the above numbers are staggered.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-10 10:50 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

You\'re echo-ing the result of printf -- since printf *outputs* the formatted value and *returns* the number of characters output, you\'re seeing the output from printf (the formatted number) followed by the output from echo (the length of the printf output).
 [2004-12-10 18:33 UTC] michael at fishnet dot us
Now do I feel stupid or what?  I've written PHP since PHP2 in 1997 and this one got by me.  Thanks for the gentle reply; I feel like I merit worse.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 20 12:01:33 2024 UTC