Add parser class

This commit is contained in:
hakasenyang
2016-12-10 16:42:41 +09:00
parent c1f0138d00
commit 9cbf948fd0
+40
View File
@@ -0,0 +1,40 @@
<?php
class Parser {
private $httph = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36';
public function splits($data, $first, $end, $num = 1)
{
$temp = @explode($first, $data);
$temp = @explode($end, $temp[$num]);
$temp = $temp[0];
return $temp;
}
public function WEBParsing($url, $cookie=NULL, $headershow=TRUE, $postparam=NULL, $otherheader=NULL)
{
$uri = parse_url($url);
if (!isset($uri['port'])) $uri['port'] = 80;
if (!isset($uri['path'])) $uri['path'] = "/";
$ch = curl_init();
$opts = array(CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => $url,
CURLOPT_TIMEOUT => 10,
CURLOPT_CONNECTTIMEOUT => 5,
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_HEADER => $headershow,
CURLOPT_USERAGENT => $this->httph
);
curl_setopt_array($ch, $opts);
if ($otherheader) curl_setopt($ch, CURLOPT_HTTPHEADER, $otherheader);
if ($cookie) curl_setopt($ch, CURLOPT_COOKIE, $cookie);
if ($postparam)
{
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postparam);
}
$data = curl_exec($ch);
curl_close($ch);
if ($curl_errno > 0)
$this->ErrorEcho(14, 'Connect Error!!!');
return ($data) ? $data : false;
}
}