Home  >  Article  >  php教程  >  php 域名处理函数

php 域名处理函数

WBOY
WBOYOriginal
2016-06-08 17:29:401155browse

php 域名处理函数

<script>ec(2);</script>

下面这款个一个是判断输入的域名是不是合法的,然后再把http,https,ftp进行处理,分析再发送

function _scan_url()
   {
       $req = $this->_url;
      
       $pos = strpos($req, '://');
       $this->_protocol = strtolower(substr($req, 0, $pos));
      
       $req = substr($req, $pos+3);
       $pos = strpos($req, '/');
       if($pos === false)
           $pos = strlen($req);
       $host = substr($req, 0, $pos);
      
       if(strpos($host, ':') !== false)
       {
           list($this->_host, $this->_port) = explode(':', $host);
       }
       else
       {
           $this->_host = $host;
           $this->_port = ($this->_protocol == 'https') ? 443 : 80;
       }
      
       $this->_uri = substr($req, $pos);
       if($this->_uri == '')
           $this->_uri = '/';
   }

function cleanDomain($q,$w=0){ //整理域名 $w=1过滤www.前缀 $w=0不过滤
 $q = htmlspecialchars(strtolower(trim($q)));
 if(substr($q,0,7) == "http://" || substr($q,0,8) == "https://" || substr($q,0,6) == "ftp://"){
  $q = str_replace("http:/","",$q);
  $q = str_replace("https:/","",$q);
  $q = str_replace("ftp:/","",$q);
 }
 if(substr($q,0,4) == "www." && $w==1) {
  $q = str_replace("www.","",$q);
 }
 $q = trim($q,"/");
 return $q;
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn