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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 02 09:01:30 2024 UTC