Created
August 8, 2016 03:21
-
-
Save anjan-virtism/8fbb752ddef8d45b86167d2030f4e413 to your computer and use it in GitHub Desktop.
Parse an URL and gets the query string as php array
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 | |
/** | |
* Parse the URL and return the query string as PHP array | |
* | |
* @param string $url | |
* | |
* @return array | |
*/ | |
function getQueryStringAsArray($url = '') { | |
$url = trim($url); | |
if(!$url) { | |
return array(); | |
} | |
$queryString = trim(parse_url($url,PHP_URL_QUERY)); | |
if(!$queryString) { | |
return array(); | |
} | |
$queryArray = array(); | |
parse_str($queryString,$queryArray); | |
return $queryArray; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment