forked from Innoz-Technologies/SMSGyan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
indore_local.php
152 lines (140 loc) · 5.11 KB
/
indore_local.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
$stime = microtime(true);
function get_between($string, $start, $end){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return false;
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
if(strpos($string,$end))
{
return substr($string,$ini,$len);
}
else
{
return false;
}
}
function multihttpget($urls) {
$mh = curl_multi_init();
foreach ($urls as $i => $oneurl) {
$ch[$i] = curl_init();
curl_setopt($ch[$i], CURLOPT_URL, $oneurl);
curl_setopt($ch[$i], CURLOPT_HEADER, 0);
curl_setopt($ch[$i], CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch[$i], CURLOPT_TIMEOUT, 100);
$useragent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
curl_setopt($ch[$i], CURLOPT_USERAGENT, $useragent);
curl_multi_add_handle($mh, $ch[$i]);
}
$active = null;
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
while ($active && $mrc == CURLM_OK) {
if (curl_multi_select($mh) != -1) {
do {
$mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);
}
}
$response = array();
foreach ($ch as $k => $h) {
$response[] = curl_multi_getcontent($h);
}
foreach ($ch as $h)
curl_multi_remove_handle($mh, $h);
curl_multi_close($mh);
return ($response);
}
function get_result($query) {
$search = trim($query);
$url = array();
$url[0] = "http://yellowpages.webindia123.com/search_pro.aspx?opt=product&q=" . urlencode($search) . "&city=Indore&street=&Submit=Go+%3E%3E";
$url[1] = "http://yellowpages.webindia123.com/search_pro.aspx?opt=company&q=" . urlencode($search) . "&city=Indore&street=&Submit=Go+%3E%3E";
$ttime = microtime(true);
return $response = multihttpget($url);
// $ttime = microtime(true) - $ttime;
}
$reqin = $req;
$ar_kw = array("indore", " in ", " at ", " on "," address ","number","contact"," of ",",");
foreach ($ar_kw as $pk) {
$reqin = str_ireplace($pk, "", $reqin);
}
$arr = array();
$loc = '';
$cont = get_result($reqin);
preg_match_all("~<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">(.+)</table></td></tr></table>~Us",$cont[0], $matches, PREG_SET_ORDER);
//print_r($matches);
foreach($matches as $mat){
$temp = $mat[1];
preg_match_all("~<a id=basic href=\"(.+)\">~Us",$temp, $matc, PREG_SET_ORDER);
foreach($matc as $ma){
$ul = "http://yellowpages.webindia123.com".$ma[1];
$arr[] = $ul;
}
}
if(count($arr) == 0){
//echo "\n<br><br>\n";
preg_match_all("~<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">(.+)</table></td></tr></table>~Us",$cont[1], $matches, PREG_SET_ORDER);
// print_r($matches);
foreach($matches as $mat){
$temp = $mat[1];
preg_match_all("~<a id=basic href=\"(.+)\">~Us",$temp, $matc, PREG_SET_ORDER);
foreach($matc as $ma){
$ul = "http://yellowpages.webindia123.com".$ma[1];
$arr[] = $ul;
}
}
}
//print_r($arr);
if(count($arr) != 0){
// print_r ($arr);
$resultt = multihttpget($arr);
//file_put_contents("loc.htm",$resultt[0]);
$imgs = array('<img src="/common_files/images/address.jpg" width="22" height="18">','<img src="/common_files/images/person.jpg" width="17" height="25">',
'<img src="/common_files/images/mobile.jpg" width="14" height="22">','<img src="/common_files/images/phone.jpg" width="20" height="14">','N/A','Get Mobile',
'X Close','Save To Mobile | Rate it','Rate it');
$start = '<table width="100%" border="0" align="right" cellpadding="0" cellspacing="0">';
$end = '<img src="/common_files/images/fax.jpg" width="21" height="18">';
$re = array();
foreach($resultt as $result){
$temp = get_between($result,$start,$end);
$tem = get_between($temp,'<script type="text/javascript">','</script>');
$temp = str_ireplace($tem,"",$temp);
$r = '<img src="/common_files/images/phone.jpg" width="20" height="14">';
$temp = str_ireplace($r, "`", $temp);
$temp = strip_tags($temp);
$temp = str_ireplace(" "," ",$temp);
foreach ($imgs as $pk) {
$temp = str_ireplace($pk, "\n", $temp);
}
while (stripos($temp, "\t") !== false) {
$temp = str_replace("\t", "", $temp);
}
$temp = str_replace("\r\n", "", $temp);
while (stripos($temp, " ") !== false) {
$temp = str_replace(" ", "", $temp);
}
$temp = str_replace("\n", "", $temp);
$re[] = $temp;
}
//print_r($re);
foreach ($re as $key => $val) {
$no = $key + 1;
$loc = $loc . "\n$no: $val";
}
$loc = str_ireplace("`", ",PH:", $loc);
$loc = trim($loc);
}
//print_r($arr);F
if (count($re) != 0) {
$files = DATA_PATH . "/loc/$global_id";
@unlink($files);
file_put_contents($files, $loc);
//echo "\n<br>location: $loc<br>\n";
$location_return = $loc;
}
$stime = microtime(true) - $stime;
echo "<br>mplocal: $stime<br>";
?>