#36980 [Opn]: [chm] bug on function.sprintf.html

From: Date: Wed, 05 Apr 2006 08:24:03 +0000
Subject: #36980 [Opn]: [chm] bug on function.sprintf.html
References: 1  Groups: php.doc 
Request: Send a blank email to phpdoc+get-969372618@lists.php.net to get a copy of this message
ID: 36980 User updated by: RQuadling at GMail dot com Reported By: RQuadling at GMail dot com Status: Open Bug Type: Documentation problem Operating System: Windows XP PHP Version: Irrelevant New Comment: 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); ?> ]]> Previous Comments: ------------------------------------------------------------------------ [2006-04-05 08:13:15] 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! ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=36980&edit=1

« previous php.doc (#969372618) next »