note 93912 added to function.array-walk
| From: | Zigbigidorlu at osu1 dot php dot net | Date: | Tue, 06 Oct 2009 17:45:34 +0000 |
| Subject: | note 93912 added to function.array-walk | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-161409@lists.php.net to get a copy of this message | ||
I tried this function to create safe SQL arrays when I'm creating query strings from keywords,
but I found it to be too bulky for my purposes. So, instead I created this function:
<?php
//Create a SQL safe array
function mysql_safe_array($array)
{
$array = array();
foreach($array as $item)
{
$safe = mysql_real_escape_string($item);
array_push($array,$safe);
unset($safe);
}
return $array;
}
//Example usage
$keywords = explode(" ",$_GET['keywords']);
$keywords = mysql_safe_array($keywords);
$query_s = implode("%' AND
field LIKE '%",$keywords);
$query = "description LIKE '%$query_s%'";
$query = stripslashes(implode(" ",$query));
?>
----
Server IP: 209.41.74.194
Probable Submitter: 71.79.182.188
----
Manual Page -- http://www.php.net/manual/en/function.array-walk.php
Edit -- https://master.php.net/note/edit/93912
Del: integrated -- https://master.php.net/note/delete/93912/integrated
Del: useless -- https://master.php.net/note/delete/93912/useless
Del: bad code -- https://master.php.net/note/delete/93912/bad+code
Del: spam -- https://master.php.net/note/delete/93912/spam
Del: non-english -- https://master.php.net/note/delete/93912/non-english
Del: in docs -- https://master.php.net/note/delete/93912/in+docs
Del: other reasons-- https://master.php.net/note/delete/93912
Reject -- https://master.php.net/note/reject/93912
Search -- https://master.php.net/manage/user-notes.php