note 102168 added to function.mysql-real-escape-string
| From: | stefan dot van dot beusekom at gmail dot com | Date: | Mon, 31 Jan 2011 13:36:01 +0000 |
| Subject: | note 102168 added to function.mysql-real-escape-string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-176527@lists.php.net to get a copy of this message | ||
Following is a recursive function that makes all the strings it finds safe for data entry. If the
underlying value is an array, it will loop through that array as well, to inifity. So any array
depth is allowed. This might come in handy when dealing with sessions, posts, gets or whatnot
arrays, where you immediately want to make use of the data without having to filter the data first.
<?php
/*
* Created by: Stefan van Beusekom
* Created on: 31-01-2011
* Description: A method that ensures safe data entry, and accepts either strings or arrays. If
the array is multidimensional,
* it will recursively loop through the array and make all points of data safe for entry.
* parameters: string or array;
* return: string or array;
*/
public function filterParameters($array) {
// Check if the parameter is an array
if(is_array($array)) {
// Loop through the initial dimension
foreach($array as $key => $value) {
// Check if any nodes are arrays themselves
if(is_array($array[$key]))
// If they are, let the function call itself over that particular node
$array[$key] = $this->filterParameters($array[$key]);
// Check if the nodes are strings
if(is_string($array[$key]))
// If they are, perform the real escape function over the selected node
$array[$key] = mysql_real_escape_string($array[$key]);
}
}
// Check if the parameter is a string
if(is_string($array))
// If it is, perform a mysql_real_escape_string on the parameter
$array = mysql_real_escape_string($array);
// Return the filtered result
return $array;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 93.125.253.100
----
Manual Page -- http://www.php.net/manual/en/function.mysql-real-escape-string.php
Edit -- https://master.php.net/note/edit/102168
Del: integrated -- https://master.php.net/note/delete/102168/integrated
Del: useless -- https://master.php.net/note/delete/102168/useless
Del: bad code -- https://master.php.net/note/delete/102168/bad+code
Del: spam -- https://master.php.net/note/delete/102168/spam
Del: non-english -- https://master.php.net/note/delete/102168/non-english
Del: in docs -- https://master.php.net/note/delete/102168/in+docs
Del: other reasons-- https://master.php.net/note/delete/102168
Reject -- https://master.php.net/note/reject/102168
Search -- https://master.php.net/manage/user-notes.php