PHP 데이터 수집 클래스 예제 코드

怪我咯
풀어 주다: 2023-03-14 07:42:01
원래의
3150명이 탐색했습니다.

데이터 수집이라고도 하는 데이터 수집은 장치를 사용하여 시스템 외부에서 데이터를 수집하고 이를 시스템에 입력하는 인터페이스입니다. 데이터 수집 기술은 다양한 분야에서 널리 활용되고 있습니다. 예를 들어 카메라와 마이크는 모두 데이터 수집 도구입니다.

수집된 데이터는 온도, 수위, 풍속, 기압 등 전기적 신호로 변환된 다양한 물리량입니다. 아날로그 양일 수도 있고 디지털 양일 수도 있습니다. 수집은 일반적으로 샘플링 방법입니다. 즉, 동일한 포인트 데이터를 특정 간격(샘플링 기간이라고 함)마다 반복적으로 수집합니다. 수집되는 데이터의 대부분은 순간적인 값일 수도 있고 일정 기간 내의 특징적인 값일 수도 있습니다. 정확한 데이터 측정은 데이터 수집의 기본입니다. 데이터 측정 방식에는 접촉식과 비접촉식이 있으며 다양한 감지 구성요소가 있습니다. 어떤 방법이나 구성 요소를 사용하더라도 데이터의 정확성을 보장하기 위해 측정 대상의 상태와 측정 환경에 영향을 주지 않는 것이 전제입니다. 데이터 수집은 표면과 같은 연속적인 물리량의 수집을 포함하여 광범위한 의미를 갖습니다. 컴퓨터를 이용한 제도, 측량, 설계에서 그래픽이나 이미지를 디지털화하는 과정을 데이터 수집이라고도 합니다. 이때 수집되는 것은 기하학적 양(또는 회색조와 같은 물리량) 데이터입니다.

오늘날 인터넷 산업의 급속한 발전과 함께 데이터 수집은 인터넷 및 분산 분야에서 널리 활용되었으며, 데이터 수집 분야에서는 중요한 변화가 일어났습니다. 우선, 분산 제어 응용 분야의 지능형 데이터 수집 시스템은 국내외에서 큰 발전을 이루었습니다. 둘째, 개인용 컴퓨터 호환 데이터 수집 시스템의 수와 마찬가지로 버스 호환 데이터 수집 플러그인의 수가 계속 증가하고 있습니다. 국내외의 다양한 데이터 수집 기계가 속속 출시되어 데이터 수집을 새로운 시대로 이끌고 있습니다.

다음은 데이터 수집 수업입니다

<? 
// 兼容 php4 php5 
// 简单调用方法 
/* 
<? 
include ("ugs.php"); // 你可以下载本ugs.phps 然后重命名为ugs.php 
$ugs = new ugs(); 
$url = "http://domainname.com/path_to_your_target?param"; 
$ugs->seturl($url); 
$ugs->gather(); 
//............这里可以调用本类里的其它方法,对$ugs->value_  做调整, 
以满足您的要求 
$content=$ugs->getcontent(); 
print($content); 
?> 
*/ 
class ugs 
{ 
    var $value_  ;  //&#39;目标内容 
    var $src_    ;  //&#39;目标URL地址 

    function seturl($url) 
    { 
        $this->src_=$url; 
    } 
    function getcontent() 
    { 
        return $this->value_; 
    } 
    function getfile($url) 
     // 获取目标 
    { 
        $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 参数非常之丰富,可以模拟各种浏览器(agent) 可以设置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) 
    //&#39;对收集到的内容中的个别字符串用新值更换/方法 
    //&#39;参数分别是旧字符串,新字符串 
    { 
        $this->value_=str_replace($oldStr,$str,$this->value_ ); 
    } 



    function cut($start,$end,$no=&#39;1&#39;,$comprise=&#39;&#39;) 
    //&#39;按指定首尾字符串对收集的内容进行裁减(不包括首尾字符串)方法 
    // $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 &#39;start&#39;: 
                        $string=$start.$string[0]; 
                break; 
                case &#39;end&#39;: 
                        $string=$string[0].$end; 
                break; 
                case &#39;all&#39;: 
                        $string=$start.$string[0].$end; 
                break; 
                default: 
                        $string=$string[0]; 
        } 
        return $this->value_=$string; 
        } 


    function  filt($head,$bot,$str,$no=&#39;1&#39;,$comprise=&#39;&#39;) 
    //&#39;按指定首尾字符串对收集的内容用新值进行替换(不包括首尾字符串)方法 
    // &#39;参数分别是首字符串,尾字符串,新值,新值位空则为过滤 
    { 
        $tmp_v=$this->value_; 
        $tmp=$this->cut($head,$bot,$no,$comprise); 
        return $this->value_=str_replace($tmp,$str,$tmp_v); 
    } 



    function  local() 
    { 
        //&#39;将收集的内容中的绝对URL地址改为本地相对地址 
        // 还没实现 
    } 



    function  replaceByReg($patrn,$str) 
     //&#39;对收集的内容中的符合正则表达式的字符串用新值进行替换/方法 
     //&#39;参数是你自定义的正则表达式,新值 
    { 
        return $this->value_=join("",preg_replace($patrn,$str,$this->value_)); 
    } 



    function debug() 
    //调试显示 
    { 
        $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(&#39;&#39;,&#39;&#39;,&#39;top=10000,left=10000&#39;);win.document.write(document.all.asdf.innerText);win.document.execCommand(&#39;SaveAs&#39;,&#39;&#39;,&#39;javascript.htm&#39;);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=\"查看效果\">  <INPUT name=Button onclick=asdf.select() type=button value=\"全选\">  <INPUT name=Button onclick=\"asdf.value=&#39;&#39;\" type=button value=\"清空\">  <INPUT onclick=saveFile(); type=button value=\"保存代码\"></center>"; 
        echo $tempstr; 
    } 


} 
?>
로그인 후 복사

위 내용은 PHP 데이터 수집 클래스 예제 코드의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!