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.
PHP Filters Advanced Example
Query for PHP/MySql AND/OR for an advanced search
PHP User Define a Function returns the string query string (q or query parameters) from the simple referrer
[php]
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;
}
[/php]
Advanced Search using PHP
[php]
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);
?>
[/php]
Web Programming Tutorials Example with Demo
Read :
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.