note 42224 added to function.sprintf
| From: | php at sharpdreams dot com | Date: | Sat, 08 May 2004 18:13:21 +0000 |
| Subject: | note 42224 added to function.sprintf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-69347@lists.php.net to get a copy of this message | ||
Note that when using the argument swapping, you MUST number every argument, otherwise sprintf gets
confused. This only happens if you use number arguments first, then switch to a non-numbered, and
then back to a numbered one.
<?php
$sql = sprintf( "select * from %1\$s left join %2\$s on( %1\$s.id = %2\$s.midpoint ) where
%1\$s.name like '%%%s%%' and %2\$s.tagname is not null", "table1",
"table2", "bob" );
// Wont work:
// Sprintf will complain about not enough arguments.
$sql = sprintf( "select * from %1\$s left join %2\$s on( %1\$s.id = %2\$s.midpoint ) where
%1\$s.name like '%%%3\$s%%' and %2\$s.tagname is not null", "table1",
"table2", "bob" );
// Will work: note the %3\$s
?>
----
Manual Page -- http://www.php.net/manual/en/function.sprintf.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42224
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42224&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42224&report=yes
Search -- http://master.php.net/manage/user-notes.php