Copy CodeThe 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 Call 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 ();
//............ Here you can call other methods in this class to make adjustments to the $ugs->value_,
To meet your requirements.
$content = $ugs->getcontent ();
Print ($content);
?>
*/
Class UGS
{
var $value _; ' Target content
var $src _; ' Destination URL address
function SetUrl ($url)
{
$this->src_= $url;
}
function GetContent ()
{
return $this->value_;
}
function GetFile ($url)
Get 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"];
$out = "GET $path http/1.0\r\nhost: $host \r\n\r\n";
$fp = Fsockopen ($host, $port, $errno, $errstr, 30);
Fwrite ($fp, $out);
$body = false;
while (!feof ($FP))
{
$s = fgets ($fp, 1024);
if ($body) $in. = $s;
if ($s = = "\ r \ n")
$body = true;
}
Fclose ($FP);
return $in;
}
function Getfile_curl ($url)
{
$curl = "/usr/local/bin/curl"; Path to your Curl
$curl _options= "-S--connect-timeout--max-time 10";
For curl usage, refer to curl--help or man curl
The curl parameter is very rich and can be simulated by various browsers (agents) to set the Referer
$cmd = "$curl $curl _options $url";
@exec ($cmd, $o, $r);
if ($r!=0)
{
return "Timeout";
}
Else
{
$o =join ("", $o);
return $o;
}
}
function Gather_curl ($curl)
{
$http = $this->getfile_curl ($this->src_);
return $this->value_= $http;
}
function Gather_array ($url)
{
Return file ($url);
}
function gather ()
Start collecting
{
$http = $this->getfile ($this->src_);
return $this->value_= $http;
}
function gather_local ($toline =true)
Working with local files
{
if ($toline)
{
$http =file ($this->src_);
return $this->value_= $this->bytestobstr ($http);
}
Else
{
$http =file ($this->src_);
return $this->value_= $http;
}
}
function Noreturn ()
Remove carriage return line break
{
$this->value_=str_replace ("\ n", "", $this->value_);
$this->value_=str_replace ("\ R", "", $this->value_);
}
function Change ($OLDSTR, $STR)
' Replace/method with a new value for individual strings in the collected content
' parameters are old string, new string
{
$this->value_=str_replace ($oldStr, $str, $this->value_);
}
function Cut ($start, $end, $no = ' 1 ', $comprise = ')
' Cuts the collected content by the specified end-to-end string (excluding the string-by-end) method
$no must be 3 ... Not allowed is 0
$comprise can choose Start or end or all or do not fill in anything
{
$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 the new value (not including the end-to-end string) method by the specified Kinsoku string
' Parameters are the first string, the trailing string, the new value, the new value bit null is the filter
{
$tmp _v= $this->value_;
$tmp = $this->cut ($head, $bot, $no, $comprise);
return $this->value_=str_replace ($tmp, $str, $tmp _v);
}
function local ()
{
' Change the absolute URL address in the collected content to a local relative address
It hasn't been realized yet.
}
function Replacebyreg ($PATRN, $STR)
' Match the regular expression string in the collected content with the new value for the replacement/method
' parameter is your custom regular expression, the new value
{
return $this->value_=join ("", Preg_replace ($patrn, $str, $this->value_));
}
function Debug ()
Debug display
{
$tempstr = " ". $this->value_."
";
Echo $tempstr;
}
}
?>
http://www.bkjia.com/PHPjc/317743.html www.bkjia.com true http://www.bkjia.com/PHPjc/317743.html techarticle Copy the code as follows:?//compatible with PHP4PHP5//program author Zhang Jian 52linux.com (I love Linux)//contact Method 733905@qq.comqq733905//Simple Call method/* *? include ("ugs.php") ;//You can ...