-
Notifications
You must be signed in to change notification settings - Fork 0
/
workerGeter.php
31 lines (26 loc) · 1.04 KB
/
workerGeter.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
<?php
function file_get_contents_curl($url) {
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,$url);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Your application name');
$query = curl_exec($curl_handle);
curl_close($curl_handle);
return $query;
}
function workerGetData($id, $folder){
$url = "http://www.shutterstock.com/pic.mhtml?id=".$id."&src=id";
$page = file_get_contents_curl($url);
preg_match_all('/<h1>.*/', $page, $title);
$title = preg_replace("/<h1>/", "", $title[0]);
preg_match_all('/id="kw_\d+".*<\/a>/', $page, $KW);
foreach ($KW[0] as $value) {
$arr[] = preg_replace(array('/.*html">/', '/<\/a>/'), "", $value);
}
$keyWords = implode(", ", $arr);
$data = array('title' => $title[0], 'keywords' => $keyWords);
$data = json_encode($data);
file_put_contents("./".$folder."/Data/".$id.".txt", $data);
}
workerGetData($argv[1], $argv[2]);