PHP Domain name handler function

Source: Internet
Author: User

The following one is to determine whether the domain name entered is legal, and then the http,https,ftp for processing, analysis and send

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) {//collating domain name $w = 1 filtering www. prefix $w =0 not filtered
  $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);
 }< br>   $q = Trim ($q, "/");
 return $q;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.