class.search.php
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php

/*
* @author Daniel Mota - http://icebeat.bitacoras.com <daniel.mota@gmail.com>
* @description Multibuscador que devuelve el primer resultado.
* @syntax search::google('icebeat');
* @return Devuelve un objeto con 4 parametros: buscador, titulo, url y numero de resultados
  */
class search {

    function
query($url,$data,$exp_count,$exp_info,$add_url='') {
        
$data = urlencode(trim($data));
        
$query = @file_get_contents($url.$data);
        
preg_match($exp_count,$query,$count);
        
preg_match($exp_info,$query,$info);
        
$host = @parse_url($url);
        
$search = new stdClass;
        
$search->search = (isset($host['host'])) ? 'http://'.$host['host'] : $url;
        
$search->title = (isset($info[2])) ? trim(strip_tags($info[2])) : '' ;
        
$search->url = (isset($info[1])) ? $add_url.trim($info[1]) : '' ;
        
$results = (empty($search->title)) ? 0 : 1;
        
$search->results = (isset($count[1])) ? trim($count[1]) : $results ;
        return
$search;
    }

    function
google($data) {
        return
search::query(
            
'http://www.google.es/search?q=',
            
$data,
            
'!aproximadamente <b>(.+)</b>!U',
            
'!<p class=g><a class=l href="(.+)">(.+)</a>!U'
            
);
    }

    function
yahoo($data) {
        return
search::query(
            
'http://es.search.yahoo.com/search?p=',
            
$data,
            
'!<div id=yschinfo>.+<strong>.+</strong>.+<strong>(.+)</strong>!Us',
            
'!<li><div><a class=yschttl  href="(.+)">(.+)</a>!U'
            
);
    }

    function
alltheweb($data) {
        return
search::query(
            
'http://alltheweb.com/search?cat=web&q=',
            
$data,
            
'!<span class="ofSoMany">(.+)</span>!U',
            
'!<span class="resTitle"><a class="res" href="(.+)" >(.+)</a>!U'
            
);
    }

    function
msn($data) {
        return
search::query(
            
'http://search.msn.com/results.aspx?q=',
            
$data,
            
'!<h5>Page 1 of (.+)\s!U',
            
'!<h2>Results</h2><ul><li><h3><a href="(.+)">(.+)</a>!U'
            
);
    }

    function
a9($data) {
        return
search::query(
            
'http://a9.com/',
            
$data,
            
'!of about(.+)</span>!Us',
            
'!a9c="web" href="(.+)" class="r-a" target="_top">(.+)</a>!U'
            
);
    }

    function
flickr($data) {
        return
search::query(
            
'http://www.flickr.com/photos/tags/',
            
$data,
            
'!<span class="DateTime">&nbsp;&nbsp;&nbsp;&nbsp;\((.+)\s!U',
            
'!class="StreamList">.+<a href="(.+)" title="(.+)"!Us',
            
'http://www.flickr.com/'
            
);
    }

    function
technorati($data) {
        return
search::query(
            
'http://technorati.com/search/',
            
$data,
            
'!class="posts-summary">.+<strong>(.+)\s!Us',
            
'!<cite><a href="(.+)" title="Read this post">(.+)</a>!U'
            
);
    }

    function
delicious($data) {
        return
search::query(
            
'http://del.icio.us/search/?all=',
            
$data,
            
'!showing 1 - 10 of(.+)</p>!Us',
            
'!<h4 class="desc"><a rel="nofollow" href="(.+)">(.+)</a></h4>!U'
            
);
    }

    function
bloglines($data) {
        return
search::query(
            
'http://bloglines.com/search?q=',
            
$data,
            
'!Results 1 - 20 of(.+)\[!Us',
            
'!<a href="/preview\?siteid=(.+)">(.+)</a>!U',
            
'http://bloglines.com/preview?siteid='
            
);
    }

    function
bitacorascom($data) {
        return
search::query(
            
'http://www.bitacoras.com/busca/',
            
$data,
            
'!Se han encontrado <strong>(.+)</strong>!U',
            
'!border="0" /></a> <a href="(.+)" class="tag">(.+)</a>!U'
            
);
    }

    function
wikipedia($data) {
        return
search::query(
            
'http://es.wikipedia.org/w/wiki.phtml?search=',
            
$data,
            
'!Results 1-20 of(.+)</strong>!U',
            
'!<li style="padding-bottom: 1em;"><a href="(.+)" title=".+">(.+)</a>!U',
            
'http://es.wikipedia.org'
            
);
    }
}

?>
PHP-Hispano.net - Porque al final, todos acabamos aprendiendo.