|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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! PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 19 23:00:01 2025 UTC |
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); ?> ]]>