Php domain name processing function
Script ec (2); script
The following one is to judge whether the entered domain name is legal, and then process http, https, and ftp, analyze and then 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) {// sort domain names $ w = 1 filter www. prefix $ w = 0 do not filter
$ Q = htmlspecialchars (strtolower (trim ($ q )));
If (substr ($ q,) = "http: //" | substr ($ q,) = "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;
}