Last active
January 4, 2023 11:37
-
-
Save dbwodlf3/7f601987f57960d2aaef843940da2e4f to your computer and use it in GitHub Desktop.
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 | |
function my_parse_url($inputString){ | |
$allowed_protocols = ["https", "http"]; | |
$input_string = $inputString; | |
$protocol = ""; | |
$hostname = ""; | |
$subdomain = ""; | |
$domain = ""; | |
$tld = ""; | |
$paths = ""; | |
$queries = []; | |
$temp; | |
$temp2; | |
foreach($allowed_protocols as $_protocol) { | |
$isProtocol = _protocol == substr($input_string, 0, count($_protocol)); | |
if(!$isProtocol){continue;} | |
$isSplitter = "://" == substr($input_string, count($_protocol), count($_protocol)+3); | |
if(!$isSplitter){break;} | |
$protocol = $_protocol; | |
} | |
if($protocol) $input_string = substr(input_string, 0, count($protocol)+3); | |
$temp = explode("/", $input_string); | |
$hostname = temp.shift(); | |
$paths = temp.join("/").split("#")[0].split("?")[0]; | |
$temp2 = temp[count(temp)-1]; | |
$temp2 = explode("#", $temp2)[0]; | |
$temp2 = explode("?", $temp2)[1]; | |
$temp2 = explode("&", $temp2); | |
if($temp2) { | |
foreach( $temp2 as $item){ | |
$_temp = explode("=", $item); | |
if(count($_temp)==2) $queries[$_temp[0]] = $_temp[1]; | |
} | |
} | |
$temp = explode(".", hostname); | |
return ["protocol"=>$protocol, "hostname"=>$hostname, "paths"=>$paths, "queries"=>$queries]; | |
} | |
print_r(my_parse_url("https://www.naver.com")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment