php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #78165 Incorrect example with printf
Submitted: 2019-06-14 17:02 UTC Modified: 2019-06-14 17:57 UTC
From: cfesting at yahoo dot com Assigned: cmb (profile)
Status: Closed Package: Strings related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2019-06-14 17:02 UTC] cfesting at yahoo dot com
Description:
------------
---
From manual page: https://php.net/function.printf
---


In example #2:

printf("[%10.10s]\n", $t); // left-justification but with a cutoff of 10 characters


It is my belief that the above will be right-justified, not left.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-06-14 17:09 UTC] girgias@php.net
-Status: Open +Status: Feedback -Package: Documentation problem +Package: Strings related
 [2019-06-14 17:09 UTC] girgias@php.net
The output is [many monke] which seems left-justified to me.


See https://3v4l.org/68s7r
 [2019-06-14 17:13 UTC] requinix@php.net
-Summary: Incorrect example +Summary: Incorrect example with printf -Status: Feedback +Status: Open
 [2019-06-14 17:13 UTC] requinix@php.net
It's kinda left-justified, kinda not, depending how you look at it.

So how about we ignore the problem entirely and change the example instead?

  printf("[%20.10s]\n", $t); // right-justification but with a cutoff of 10 characters
  printf("[%-20.10s]\n", $t); // left-justification but with a cutoff of 10 characters

with output

  [          many monke]
  [many monke          ]
 [2019-06-14 17:42 UTC] cmb@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2019-06-14 17:56 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=347601
Log: Fix #78165: Incorrect example with printf

We also remove the useless self-reference from the "see also" section.
 [2019-06-14 17:57 UTC] cmb@php.net
-Status: Verified +Status: Closed
 [2019-06-14 17:57 UTC] cmb@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.
 [2019-06-14 18:00 UTC] salathe@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=d19191720ea679022901958863e453f31c149455
Log: Fix #78165: Incorrect example with printf
 [2020-02-07 06:05 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=381e8ebf1be03abccb6d6a7d44488dcb1c56a0bd
Log: Fix #78165: Incorrect example with printf
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 03:01:27 2024 UTC