Home >Backend Development >PHP Tutorial >Wireless data collection A data collection class
Copy the code The code is as follows:
// Compatible with php4 php5
// Program author Zhang Jian 52linux.com (I love Linux)
// Contact method 733905@qq.com QQ 733905
// Simple calling method
/*
< ?
include ("ugs.php"); // You can download this ugs.phps and rename it to ugs.php
$ugs = new ugs();
$url = "http://domainname.com/path_to_your_target ?param";
$ugs->seturl($url);
$ugs->gather();
//............ Other methods in this class can be called here , adjust $ugs->value_ to meet your requirements
$c
print($content);
?>
*/
class ugs
{
var $value_ ; //'Target content
var $src_ ; //'Target URL address
function seturl turn $this->value_;
}
Function getfile($url)
//Get the target
{
$url_parsed = parse_url($url);
$host = $url_parsed["host"];
$port = $url_ parsed["port"];
if ($port==0) $port = 80;
$path = $url_parsed["path"];
if (empty($path))
$path="/";
if ($url_parsed["query" ] != "")
$path .= "?".$url_parsed["query"];
port, $errno, $errstr, 30);
. fgets($fp, 1024) ; IF ($ Body) $ in. = $ S;
if ($ s == "rn")
$ body = true;
}
fclose ($ fp);
Return $ in; ($url)
{
$curl="/usr/local/bin/curl "; // path to your curl
$curl_opti
// For curl usage, please refer to curl --help or man curl
// curl parameters are very It is so rich that it can simulate various browsers (agents) and can set referer
$cmd="$curl $curl_options $url ";
@exec($cmd,$o,$r);
if($r!=0 ) }
function gather_curl($curl)
$this->getfile_curl($this->src_);
return $this->value_=$http;
function gather_array($url)
{
return file($url);
}
function gather()
// 开始收集
{
$http=$this->getfile($this->src_);
return $this->value_=$http;
}
function gather_local($toline=true)
// 处理本地文件
{
if($toline)
{
$http=file($this->src_);
return $this->value_=$this->BytesToBstr($http);
}
else
{
$http=file($this->src_);
return $this->value_=$http;
}
}
function noReturn()
// 删除回车换行
{
$this->value_=str_replace("n","",$this->value_);
$this->value_=str_replace("r","",$this->value_);
}
function change($oldStr,$str)
//'对收集到的内容中的个别字符串用新值更换/方法
//'参数分别是旧字符串,新字符串
{
$this->value_=str_replace($oldStr,$str,$this->value_ );
}
function cut($start,$end,$no='1',$comprise='')
//'按指定首尾字符串对收集的内容进行裁减(不包括首尾字符串)方法
// $no 必须是 1,2 3 ... 不允许是0
//$comprise 可以选择 start 或者 end 或者 all 或者 什么都不填
{
$string=explode($start,$this->value_);
//print_r($string);
$string=explode($end,$string[$no]);
//print_r($string);
switch ($comprise){
case 'start':
$string=$start.$string[0];
break;
case 'end':
$string=$string[0].$end;
break;
case 'all':
$string=$start.$string[0].$end;
break;
default:
$string=$string[0];
}
return $this->value_=$string;
}
function filt($head,$bot,$str,$no='1',$comprise='')
//'Replace the collected content with new values according to the specified first and last strings (excluding the first and last strings) ) method
($ head, $ bot, $ no, $ comprise);
Return $ this- & gt; value_ = str_replace ($ TMP, $ Str, $ TMP_V); Collect Change the absolute URL address in the content to a local relative address
// It has not been implemented yet
}
function replaceByReg($patrn,$str)
// 'Use new values for strings that match regular expressions in the collected content Perform replacement/method // 'parameter is your custom regular expression, new value {
return $ this- & gt; value_ = join ("", preg_replace ($ patrn, $ str, $ this- & gt; value_ ));
}
function debug()
//Debug display
{
$tempstr="<SCRIPT>function runEx(){var winEx2 = window.open("", "winEx2", "width=500, height=300,status=yes,menubar=no,scrollbars=yes,resizable=yes"); winEx2.document.open("text/html", "replace"); winEx2.document.write(unescape(event.srcElement .parentElement.children[0].value)); winEx2.document.close(); }function saveFile(){var win=window.open('','','top=10000,left=10000'); win.document.write(document.all.asdf.innerText);win.document.execCommand('SaveAs','','javascript.htm');win.close();}</SCRIPT>