Get search query string from search engines using PHP

Today, We want to share with you Get search query string from search engines using PHP.In this post we will show you wordpress plugin require another plugin, hear for How to create your own search engine with PHP and MySQL we will give you demo and example for implement.In this post, we will learn about how to create search engine in php and mysqli with an example.

Get search query string from search engines using PHP

There are the Following The simple About how to create a search engine like google in html Full Information With Example and source code.

As I will cover this Post with live Working example to develop php search engine script for mysql database, so the simple search engine in php and mysql source code is used for this example is following below.

READ :  How to get last executed mysql query in laravel 6?

PHP Filters Advanced Example

Query for PHP/MySql AND/OR for an advanced search

E-junkie: Sell digital downloads online

E-junkie Provides a Copy-paste buy-now, and cart buttons for selling downloads, codes and tangible products on any website, blog, social media, email and messenger!

Also see:

  1. The Top 10+ Best Webinar Software Platforms For 2020-2021
  2. Build Your Future Godaddy Careers And Jobs
  3. Introduction To Web Hosting Services

PHP User Define a Function returns the string query string (q or query parameters) from the simple referrer

function get_search_query()
{
    $main_keywords = '';
  
    $referrer = $_SERVER['HTTP_REFERER'];
    if (!empty($referrer))
    {
        $parts_url = parse_url($referrer);
 
        $query = isset($parts_url['query']) ? $parts_url['query'] : '';
        if($query)
        {
            parse_str($query, $qur_str);
            $main_keywords = isset($qur_str['q']) ? $qur_str['q'] : (isset($qur_str['query']) ? $qur_str['query'] : '' );
        }
    }
    return $main_keywords;
}

Advanced Search using PHP

<php
	$db = mysqli_connect("localhost", "root", "", "pakainfo_web");	
	$with_any_one_of = "";
	$with_the_exact_of = "";
	$without = "";
	$starts_with = "";
	$search_in = "";
	$advance_search_submit = "";
	
	$user_qry_string = "";
	if(!empty($_POST["search"])) {
		$advance_search_submit = $_POST["advance_search_submit"];
		foreach($_POST["search"] as $k=>$v){
			if(!empty($v)) {

				$queryCases = array("with_any_one_of","with_the_exact_of","without","starts_with");
				if(in_array($k,$queryCases)) {
					if(!empty($user_qry_string)) {
						$user_qry_string .= " AND ";
					} else {
						$user_qry_string .= " WHERE ";
					}
				}
				switch($k) {
					case "with_any_one_of":
						$with_any_one_of = $v;
						$dataContent = explode(" ", $v);
						$wordsCount = count($dataContent);
						for($i=0;$i<$wordsCount;$i++) {
							if(!empty($_POST["search"]["qry_str"])) {
								$user_qry_string .= $_POST["search"]["qry_str"] . " LIKE '%" . $dataContent[$i] . "%'";
							} else {
								$user_qry_string .= "title LIKE '" . $dataContent[$i] . "%' OR information LIKE '" . $dataContent[$i] . "%'";
							}
							if($i!=$wordsCount-1) {
								$user_qry_string .= " OR ";
							}
						}
						break;
					case "with_the_exact_of":
						$with_the_exact_of = $v;
						if(!empty($_POST["search"]["qry_str"])) {
							$user_qry_string .= $_POST["search"]["qry_str"] . " LIKE '%" . $v . "%'";
						} else {
							$user_qry_string .= "title LIKE '%" . $v . "%' OR information LIKE '%" . $v . "%'";
						}
						break;
					case "without":
						$without = $v;
						if(!empty($_POST["search"]["qry_str"])) {
							$user_qry_string .= $_POST["search"]["qry_str"] . " NOT LIKE '%" . $v . "%'";
						} else {
							$user_qry_string .= "title NOT LIKE '%" . $v . "%' AND information NOT LIKE '%" . $v . "%'";
						}
						break;
					case "starts_with":
						$starts_with = $v;
						if(!empty($_POST["search"]["qry_str"])) {
							$user_qry_string .= $_POST["search"]["qry_str"] . " LIKE '" . $v . "%'";
						} else {
							$user_qry_string .= "title LIKE '" . $v . "%' OR information LIKE '" . $v . "%'";
						}
						break;
					case "qry_str":
						$qry_str = $_POST["search"]["qry_str"];
						break;
				}
			}
		}
	}
	$orderby = " ORDER BY id desc"; 
	$query_sql = "SELECT * FROM users " . $user_qry_string;
	$result = mysqli_query($db,$query_sql);
?>

Web Programming Tutorials Example with Demo

Read :

READ :  Vuejs Form Validation Example - vue validation

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about How to Create a Search Feature with PHP and MySQL.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.