note 96440 added to function.sprintf
| From: | php at emanaton dot com | Date: | Sat, 27 Feb 2010 03:12:21 +0000 |
| Subject: | note 96440 added to function.sprintf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-166424@lists.php.net to get a copy of this message | ||
Jay Gilford provided a very nice bit of code for use in escaping arguments for a mysql_query
gracefully, and I've expanded on the idea a bit; for those that are having trouble parsing his
and my function name, it stands for "Mysql_Real_Escape_String SprintF Mysql_Query":
<?php
/**
* The first argument must be the sql statement with placeholders. After being
* escaped, all the args that follow are combined into this argument using
* sprintf();
*
* NOTE: This function based on code from
* http://us3.php.net/manual/en/function.sprintf.php#93156
*/
function mressfmq() {
$args = func_get_args();
// Gracefully deal with situations where no arguments are passed or where
// only an SQL statement is provided.
switch (count($args)) {
case 0:
return false;
case 1:
return mysql_query($args[0]);
}
$query = array_shift($args); // the first argument is the query
$args = array_map('mysql_real_escape_string', $args); // sanitize the args
array_unshift($args, $query); // stick the query back in the args array...
$query = call_user_func_array('sprintf', $args); //... for use with sprintf
return mysql_query($query);
}
?>
----
Server IP: 192.41.40.227
Probable Submitter: 24.210.106.192
----
Manual Page -- http://www.php.net/manual/en/function.sprintf.php
Edit -- https://master.php.net/note/edit/96440
Del: integrated -- https://master.php.net/note/delete/96440/integrated
Del: useless -- https://master.php.net/note/delete/96440/useless
Del: bad code -- https://master.php.net/note/delete/96440/bad+code
Del: spam -- https://master.php.net/note/delete/96440/spam
Del: non-english -- https://master.php.net/note/delete/96440/non-english
Del: in docs -- https://master.php.net/note/delete/96440/in+docs
Del: other reasons-- https://master.php.net/note/delete/96440
Reject -- https://master.php.net/note/reject/96440
Search -- https://master.php.net/manage/user-notes.php