note 71253 added to function.vsprintf
| From: | iisys_ at hotmail dot com | Date: | Sun, 19 Nov 2006 18:29:15 +0000 |
| Subject: | note 71253 added to function.vsprintf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-119872@lists.php.net to get a copy of this message | ||
I've made this simple function for more compatibility with different applications.
As arguments, it can accept an array or single arguments.
<?php
function asprintf() {
$a = func_get_args();
$format = array_shift($a);
if (is_array($a[0])) {
$a = $a[0];
}
return vsprintf($format, $a);
}
# Examples.
$sql_arguments = array('fields' => '*', 'table' =>
'users', 'field' => 'user', 'value' =>
'exploited');
echo asprintf("SELECT %s FROM %s WHERE %s = '%s'", $sql_arguments);
# Would output: SELECT * FROM users WHERE user = 'exploited'
echo asprintf("SELECT %s FROM %s WHERE %s = '%s'", '*',
'users', 'user', 'exploited');
# Would output the same.
?>
----
Server IP: 83.137.20.120
Probable Submitter: 80.57.186.104
----
Manual Page -- http://www.php.net/manual/en/function.vsprintf.php
Edit -- https://master.php.net/note/edit/71253
Del: integrated -- https://master.php.net/note/delete/71253/integrated
Del: useless -- https://master.php.net/note/delete/71253/useless
Del: bad code -- https://master.php.net/note/delete/71253/bad+code
Del: spam -- https://master.php.net/note/delete/71253/spam
Del: non-english -- https://master.php.net/note/delete/71253/non-english
Del: in docs -- https://master.php.net/note/delete/71253/in+docs
Del: other reasons-- https://master.php.net/note/delete/71253
Reject -- https://master.php.net/note/reject/71253
Search -- https://master.php.net/manage/user-notes.php