note 121893 added to function.vsprintf
| From: | ASchmidt at Anamera dot net | Date: | Tue, 21 Nov 2017 18:58:41 +0000 |
| Subject: | note 121893 added to function.vsprintf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-209187@lists.php.net to get a copy of this message | ||
It's necessary to clearly how to apply argument swapping when using an array of arguments. One
might be tempted to use %0$ to reference $args[0].
In reality, the position specifier is always the array index+1:
$args[0] is referenced by %1$...
$args[1] is referenced by %2$...
etc.
Similarly, the first subpattern of a RegEx match would be found in $matches[1], the second in
$match[2], etc. However if the $matches array is used as arguments to vsprint(), then the position
specifier is subpattern+1:
preg_match( $pattern, $subject, $matches );
vsprintf( 'Full Match = %1$s, first Subpattern = %2$s, second Subpattern = %3$s', $matches
);
----
Server IP: 208.43.231.9
Probable Submitter: 173.63.128.218
----
Manual Page -- http://php.net/manual/en/function.vsprintf.php
Edit -- https://master.php.net/note/edit/121893
Del: integrated -- https://master.php.net/note/delete/121893/integrated
Del: useless -- https://master.php.net/note/delete/121893/useless
Del: bad code -- https://master.php.net/note/delete/121893/bad+code
Del: spam -- https://master.php.net/note/delete/121893/spam
Del: non-english -- https://master.php.net/note/delete/121893/non-english
Del: in docs -- https://master.php.net/note/delete/121893/in+docs
Del: other reasons-- https://master.php.net/note/delete/121893
Reject -- https://master.php.net/note/reject/121893
Search -- https://master.php.net/manage/user-notes.php