php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28809 output error on =printf
Submitted: 2004-06-17 00:11 UTC Modified: 2004-07-08 12:19 UTC
From: chris at arbo-com dot fr Assigned:
Status: Not a bug Package: Output Control
PHP Version: 4.3.7 OS: linux redhat 7.3 kernel 2.4.x
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: chris at arbo-com dot fr
New email:
PHP Version: OS:

 

 [2004-06-17 00:11 UTC] chris at arbo-com dot fr
Description:
------------
when use printf with <?=printf
the output is not identical at older version of php

Now the printf send the true string, but add after the nombre of send caractere.

the documentation of printf retur void et not the nombre of caractere send.

Reproduce code:
---------------
<?
        for($i=0; $i<=4; $i++)
        {
?>
my line <?=printf("%02d<br>",$i) ?>
<?php

        }
?>

Expected result:
----------------
with old version printf not send nombre of caractere write on flux.

Actual result:
--------------
my line 00
6my line 01
6my line 02
6my line 03
6my line 04
6

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-18 19:18 UTC] imprestavel at gameguru dot com dot br
True. Printf changed behavior, now it seems to return result string length (instead of void).
But I think there is also a bug in your code:
<?=printf("%02d<br>",$i)?>
  ^^

You could try:
<?=sprintf("%02d<br>",$i)?>
or:
<?printf("%02d<br>",$i);?>

Because <?='string'?> echoes 'string'
This means that it will echo the return of printf. When it was void, there was no visual problem.
 [2004-07-08 12:19 UTC] sniper@php.net
Buggy user code. There's nothing wrong with printf() or <?=

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 06 20:01:35 2025 UTC