How to build a Meta search engine using php and google

3 min read

How to build a meta search engine with PHP

meta search engine is a search tool that sends user requests to several other search engines and/or databases and aggregates the results into a single list or displays them according to their source.Currently there are a lot of meta search engine on internet.For example deeperweb.com is a meta search engine which gives the normal search results of google  combined with  results of  “Answers Search” ,”Metrics Search” ,”News Search” etc.In this tutorial I will show you how to build a meta search engine with PHP .

Meta Search Engine

To build a meta search engine first you need to choose a real search engine and here nothing is better that google.com. Now you need to fetch the content of google search and curl() is the best method for PHP.After fetching the results you need to you need to parse the search results because there are a lot of other things which are useless for you.I have used regular expressions for parsing .After parsing results and exacting main information from content you just need to show the results in your manner.

You can see the demo of my meta search engine script from here.

Here is the source of  this meta search engine.

Meta Search Engine PHP Script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
//Date:30-11-2012
//Title:How to build a meta search engine with PHP
//File name:meta-search.php
if(!isset($_GET['q']))$extra='form{
position:absolute;
top:200px;
left:500px;
}';
echo'<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Meta Search Engine By megarush.net</title>
<style type="text/css">.
body
{
font-size: small;
    font-family: arial,sans-serif;}
a
{
color:#12C;
}
li
{
list-style:none;}
cite
{
color:#093;
}
.st
{
line-height: 1.24;
font-size: small;
    font-family: arial,sans-serif;}
.q{
width:300px;
height:30px;
font-size:19px;}
.bt
{
width:70px;
height:30px;
font-size:19px;
}
'.$extra.'
</style>
</head>
<body>
<form >
<input type="text" class="q" name="q" value="'.$_GET["q"].'" />
<input type="submit" class="bt" value="search" />
</form>';
if(isset($_GET['q'])){
$q=$_GET['q'];
$dork="";// (optional)specify a dork if you want to use like site:php.net etc
$site="google.com";   // choose any country based search engine by google linke google.co.in ,google.co.uk etc;
$link="http://www.".$site."/search?q=".$q.$dork;
$link=str_replace(" ","%20",$link);
$ch=curl_init();
$useragent="Mozilla/5.0 (compatible; Megarush bot; +http://megarush.net/meta-search-engine-php/)";   //Choose a user agent
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_URL,$link);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$content = curl_exec($ch);
curl_close($ch);
//$content =file_get_contents($link);    //if you are unable to use curl then use this method to fetch data
preg_match_all('/<li class="g">.+?<\/li>/',$content,$con);
if(count($con[0])==0) echo "No results found";
for($i=0;$i<count($con[0]);$i++)
{
$con[0][$i]=preg_replace('/\/url\?q=/','',$con[0][$i]);
$con[0][$i]=preg_replace('/\/search\?/','/meta-search.php?',$con[0][$i]);
$con[0][$i]=preg_replace('/\/imgres\?imgurl=/','http://'.$site."/imgres?imgurl=",$con[0][$i]);
$con[0][$i]=preg_replace('/\/images\?q=/','http://'.$site."/images?q=",$con[0][$i]);
$con[0][$i]=str_replace('%3F','?',$con[0][$i]);
$con[0][$i]=str_replace('%3D','=',$con[0][$i]);
$con[0][$i]=str_replace('&amp;sa','?&sa',$con[0][$i]);
echo $con[0][$i];
}}
?>
</body>
</html>

 

You can customize this PHP script by implementing google dork and you can show unique search results .For example if you want to build a video search engine than can use site:youtube.com as a dork to show results only from YouTube.

Total Execution Time content: 0.00048720041910807 Mins Total Execution Time social : 0.0001 Mins

Read Next

Total Execution Time red next: 0.0000 Mins

Search Now






Categories