note 93912 deleted from function.array-walk by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 11:17:18 +0000 |
| Subject: | note 93912 deleted from function.array-walk by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197076@lists.php.net to get a copy of this message | ||
Note Submitter: Zigbigidorlu
----
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));
?>