Last active
July 19, 2018 12:58
-
-
Save saderi/dbcd34f87f55aca7d167df7e05e9453c to your computer and use it in GitHub Desktop.
update php parse_url function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Update php parse_url function | |
// It determines that URL is a domain or IP by is_ip | |
// Define clean site url without path | |
function plus_parse_url($url) { | |
if(!preg_match("/^[a-zA-Z0-9]+$/", substr($url,0,1))) | |
return false; | |
if (strpos($url,"://")) { | |
$parse = parse_url(strtolower($url)); | |
$parse['is_ip'] = (preg_match("/^[0-9]+$/", substr($parse['host'],-1)))? true : false; | |
if ($parse['scheme'] == 'http') { | |
$parse['port'] = 80; | |
} elseif ($parse['scheme'] == 'https') { | |
$parse['port'] = 443; | |
} else { | |
$parse['port'] = 0; | |
} | |
$parse['site_url'] = $parse['scheme'].'://'.$parse['host']; | |
return $parse; | |
} | |
$url = "non-protocol://".$url; | |
$parse = parse_url(strtolower($url)); | |
$parse['port'] = 0; | |
$parse['is_ip'] = (preg_match("/^[0-9]+$/", substr($parse['host'],-1)))? true : false; | |
if (isset($parse['path']) || !$parse['is_ip']) { | |
$parse['site_url'] = 'http://'.$parse['host']; | |
$parse['port'] = 80; | |
} | |
return $parse; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment