diff --git a/functions/strings.xml b/functions/strings.xml index c05d88bf5d..5db6b0d915 100644 --- a/functions/strings.xml +++ b/functions/strings.xml @@ -1915,6 +1915,48 @@ soundex ("Lukasiewicz") == soundex ("Lissajous") == 'L222'; + + As of PHP version 4.0.6 the format string supports argument + numbering/swapping. Here is an example: + + Argument swapping + +$format = "There are %d monkeys in the %s"; +printf($format,$num,$location); + + + This might output, "There are 5 monkeys in the tree". But imagine we are + creating a format string in a separate file, commonly because we would like to + internationalize it and we rewrite it as: + + Argument swapping + +$format = "The %s contains %d monkeys"; +printf($format,$num,$location); + + + We now have a problem. The order of the placeholders in the format string + does not match the order of the arguments in the code. We would like to + leave the code as is and simply indicate in the format string which arguments + the placeholders refer to. We would write the format string like this + instead: + + Argument swapping + +$format = "The %2\$s contains %1\$d monkeys"; +printf($format,$num,$location); + + + An added benefit here is that you can repeat the placeholders without + adding more arguments in the code. For example: + + Argument swapping + +$format = "The %2\$s contains %1\$d monkeys. That's a nice %2\$s full of %1\$d monkeys."; +printf($format,$num,$location); + + + See also: printf, sscanf, fscanf, and number_format.