最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

一個數(shù)據(jù)采集類

 更新時間:2007年02月14日 00:00:00   作者:  
復(fù)制代碼 代碼如下:

<?
// 兼容 php4 php5
// 程序作者  張建 52linux.com(我愛Linux)
// 聯(lián)系方法  733905@qq.com  QQ 733905 
// 簡單調(diào)用方法
/*
<?
include ("ugs.php"); // 你可以下載本ugs.phps 然后重命名為ugs.php
$ugs = new ugs();
$url = "http://domainname.com/path_to_your_target?param";
$ugs->seturl($url);
$ugs->gather();
//............這里可以調(diào)用本類里的其它方法,對$ugs->value_  做調(diào)整,
以滿足您的要求
$content=$ugs->getcontent();
print($content);
?>
*/
class ugs
{
    var $value_  ;  //'目標(biāo)內(nèi)容
    var $src_    ;  //'目標(biāo)URL地址

    function seturl($url)
    {
        $this->src_=$url;
    }
    function getcontent()
    {
        return $this->value_;
    }
    function getfile($url)
     // 獲取目標(biāo)
    {
        $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 10  --max-time 10  "; 
    // curl 用法請參考 curl --help 或者 man curl 
    // curl 參數(shù)非常之豐富,可以模擬各種瀏覽器(agent) 可以設(shè)置referer
    $cmd="$curl $curl_options $url ";
    @exec($cmd,$o,$r);
    if($r!=0) 
    {
        return "超時";
    }
    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()
     // 開始收集
    {
        $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)
    //'對收集到的內(nèi)容中的個別字符串用新值更換/方法
    //'參數(shù)分別是舊字符串,新字符串
    {
        $this->value_=str_replace($oldStr,$str,$this->value_ );
    }



    function cut($start,$end,$no='1',$comprise='')
    //'按指定首尾字符串對收集的內(nèi)容進(jìn)行裁減(不包括首尾字符串)方法
    // $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='')
    //'按指定首尾字符串對收集的內(nèi)容用新值進(jìn)行替換(不包括首尾字符串)方法
    // '參數(shù)分別是首字符串,尾字符串,新值,新值位空則為過濾
    {
        $tmp_v=$this->value_;
        $tmp=$this->cut($head,$bot,$no,$comprise);
        return $this->value_=str_replace($tmp,$str,$tmp_v);
    }



    function  local()
    {
        //'將收集的內(nèi)容中的絕對URL地址改為本地相對地址
        // 還沒實現(xiàn)
    }



    function  replaceByReg($patrn,$str)
     //'對收集的內(nèi)容中的符合正則表達(dá)式的字符串用新值進(jìn)行替換/方法
     //'參數(shù)是你自定義的正則表達(dá)式,新值
    {
        return $this->value_=join("",preg_replace($patrn,$str,$this->value_));
    }



    function debug()
    //調(diào)試顯示
    {
        $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><center><TEXTAREA id=asdf name=textfield rows=32  wrap=VIRTUAL cols=\"120\">".$this->value_."</TEXTAREA><BR><BR><INPUT name=Button onclick=runEx() type=button value=\"查看效果\">&nbsp;&nbsp;<INPUT name=Button onclick=asdf.select() type=button value=\"全選\">&nbsp;&nbsp;<INPUT name=Button onclick=\"asdf.value=''\" type=button value=\"清空\">&nbsp;&nbsp;<INPUT onclick=saveFile(); type=button value=\"保存代碼\"></center>";
        echo $tempstr;
    }


}
?>

相關(guān)文章

最新評論

凌源市| 潢川县| 于都县| 锦州市| 葫芦岛市| 兴宁市| 镇康县| 台南市| 盐城市| 洞口县| 偃师市| 锡林郭勒盟| 朝阳市| 安龙县| 蒙阴县| 正镶白旗| 丹阳市| 乌鲁木齐县| 胶州市| 朝阳区| 双桥区| 平谷区| 英超| 师宗县| 铁岭市| 东阳市| 时尚| 枞阳县| 会同县| 固阳县| 永春县| 儋州市| 芦山县| 辽中县| 沂源县| 正蓝旗| 萨嘎县| 瓮安县| 石泉县| 古浪县| 揭东县|