Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to search two or more words in php using explode and implode function ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.23k
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: