php error_reporting id 79936 function get_id link preg_match 0-9 link

 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
<?php
error_reporting(0);
$id = 79936;
function get_id($link){
preg_match("/r=([0-9]{1,})/", $link, $link2);
return $link2[1];
}
function show_new(&$topics, &$times, &$authors, $id){
$c = 0;
for($i=0;$i<=count($times[1])-1;$i++){
if($id < get_id($topics[1][$i])){
$c++;
$n .= "Тема: ".$topics[2][$i]."\nДата: ".$times[1][$i]."\nАвтор: ".$authors[1][$i]."\nСсылка: http://spaces.ru/forums/?r=".get_id($topics[1][$i])."\n\n";
}
}
return "В сообществе появилось $c новых тем!\n\n".$n;
}
function vk($method, $data, $token=""){
$url="https://api.vk.com/method/".$method;
if($curl = curl_init()){
curl_setopt($curl,CURLOPT_URL,$url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
$data['access_token'] = $token;
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$out = curl_exec($curl);
return json_decode($out, true);
curl_close($curl);
}
}
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => "http://spaces.ru/forums/?com_cat_id=".$id."&last=6&tp=1",
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HEADER => 1
));
$out = curl_exec($ch);
curl_close($ch);
preg_match_all('#</span>
<a href="(.*?)" class="arrow_link"><span>(.*?)</span></a>#u', $out, $topics);
preg_match_all('#<span class="comment_date right_fix">(.*?)</span>#u', $out, $times);
preg_match_all('#<small class="grey">(.*?) / (.*?)</small>#u', $out, $authors);
$memcache_obj = new Memcache;
$memcache_obj->connect('127.0.0.1', 11211) or die("Could not connect");
$last_id = @$memcache_obj->get('last_id');
if($last_id != get_id($topics[1][0])){
echo "\n\nЕсть новые темы!";
vk("messages.send", array(
"chat_id" => 15,
"message" => show_new($topics, $times, $authors, $last_id),
));
$memcache_obj->set('last_id', get_id($topics[1][0]), false, 0);
}
$memcache_obj->close();