php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #36980 [chm] bug on function.sprintf.html
Submitted: 2006-04-05 08:13 UTC Modified: 2006-04-05 16:13 UTC
From: RQuadling at GMail dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: Windows XP
Private report: No CVE-ID: None
 [2006-04-05 08:13 UTC] RQuadling at GMail dot com
Description:
------------
I have found a bug on page function.sprintf.html
[chm date: 2006-04-03]...

The examples regarding the facility of argument swapping all use double quotes. As a consequence, the parameters need to escape the $ in the format so to tell PHP to not evaluate $s.

e.g.

"%1\$s"

As the basic idea here is to use these markers as placeholders for data from elsewhere, the emphasis is surely that these are plaintext strings, not strings with embedded variables, otherwise, what's the point of the function? Yeah, I know formatting, but you can't format a variable if you supply it IN the string, so hopefully, my reasoning still stands.

The examples should be ...

'%1$s' This makes more sense.

All the examples and a lot of the user notes ALL use the 'suspect' double quotes.

The user note by moritz dot geselle at invision-team dot de on 02-Dec-2002 10:52 (http://uk2.php.net/manual/en/function.sprintf.php#27346) should be taken into account and the docs reflect this simply because it is NOT obvious!




Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-05 08:24 UTC] RQuadling at GMail dot com
Possible patch.

Index: sprintf.xml
===================================================================
RCS file: /repository/phpdoc/en/reference/strings/functions/sprintf.xml,v
retrieving revision 1.15
diff -u -r1.15 sprintf.xml
--- sprintf.xml 28 Nov 2004 12:42:49 -0000      1.15
+++ sprintf.xml 5 Apr 2006 08:21:45 -0000
@@ -143,7 +143,7 @@
       <programlisting role="php">
 <![CDATA[
 <?php
-$format = "There are %d monkeys in the %s";
+$format = 'There are %d monkeys in the %s';
 printf($format, $num, $location);
 ?>
 ]]>
@@ -158,7 +158,7 @@
       <programlisting role="php">
 <![CDATA[
 <?php
-$format = "The %s contains %d monkeys";
+$format = 'The %s contains %d monkeys';
 printf($format, $num, $location);
 ?>
 ]]>
@@ -174,7 +174,7 @@
       <programlisting role="php">
 <![CDATA[
 <?php
-$format = "The %2\$s contains %1\$d monkeys";
+$format = 'The %2$s contains %1$d monkeys';
 printf($format, $num, $location);
 ?>
 ]]>
@@ -187,8 +187,8 @@
       <programlisting role="php">
 <![CDATA[
 <?php
-$format = "The %2\$s contains %1\$d monkeys.
-           That's a nice %2\$s full of %1\$d monkeys.";
+$format = 'The %2$s contains %1$d monkeys.
+           That's a nice %2$s full of %1$d monkeys.';
 printf($format, $num, $location);
 ?>
 ]]>
 [2006-04-05 16:13 UTC] vrana@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.

BTW there's a mistake on the last modified line of your patch.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 08 20:01:34 2025 UTC