-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTelegramPublicSearch.php
43 lines (29 loc) · 1 KB
/
TelegramPublicSearch.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
<?php
/*
* A Simple Code To Search Through Public Channels in Telegram
*
* https://github.com/kihanb/TelegramPublicSearch/
*
*/
function TelegramPublicSearch($channel_id , $query ='', $limit = 5){
$geturl = "https://t.me/s/$channel_id?q=" . urlencode($query);
$posts = array();
$founded = 0;
while(true){
$get = file_get_contents($geturl);
if(preg_match_all('/<a class="tgme_widget_message_date" href="(.*?)">/', $get, $items)){
foreach($items[1] as $item){
$founded++;
if($founded <= $limit)
$posts[] = $item;
else
break;
}
$geturl = "https://t.me/s/$channel_id?q=" . urlencode($query) . '&before=' . str_replace('https://t.me/'. $channel_id . '/','',$items[1][0]);
}else{
break;
}
}
return $posts;
}
?>