-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMisc.php
More file actions
41 lines (33 loc) · 1.04 KB
/
Copy pathMisc.php
File metadata and controls
41 lines (33 loc) · 1.04 KB
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
<?php
class Misc {
public static function analyze($message) {
$result = array();
// fetch url page titles
$matches = array();
$regex = "/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i";
preg_match_all($regex, $message, $matches);
foreach ($matches[0] as $url) {
$title = array();
$str = file_get_contents($url);
if(strlen($str)>0){
preg_match("/<title>(.*)<\/title>/i",$str,$title);
if ( strlen($title[1]) > 0 ) {
$result[] = "^ " . $title[1];
}
}
}
return $result;
}
public static function getUrl($url){
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
}
?>