How to search words in php using explode and implode function?:
I am posting this blog as many php coders got stuck while searching multiple terms using implode and explode. I have the form in which users are going to search multiple terms.
Here is the code
$my_explode = explode(" ",$search);
$query = array();
foreach($my_explode as $string)
{
$query[] ="name LIKE '%".$string."%' OR email LIKE '%".$string."%'";
}
$implode = implode(' OR ', $query);
foreach ($db->query("SELECT * FROM _table WHERE ".$implode."") as $info)
{
echo $info['name']."<br />";
}
Secure for injection, with php retrieve just alphanumeric chars
$search = preg_replace("/[^a-zA-Z0-9]+/", "-", $_GET["text"]);
Hope this will going to solve the issue for searching using implode and explode.
Thanks for reading
0 Comment(s)