Last active
September 7, 2017 09:53
-
-
Save azeemhassni/b435f0c86147c9792693 to your computer and use it in GitHub Desktop.
Decode URL formed query
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 | |
/** | |
* Decode URL formed strings | |
* @param $string | |
* @return array | |
* @author Azeem Hassni <http://azeemhassni.com> | |
*/ | |
function decode_query($string) { | |
$vars = explode('&',$string); | |
$return = array(); | |
foreach($vars as $var) { | |
$exp_var = explode('=', $var); | |
$return[$exp_var[0]] = $exp_var[1]; | |
} | |
return $return; | |
} | |
/** | |
* Example Usage | |
* $url_query = 'q=lorem+ipsum&ordeby=name&order=desc'; | |
* calling : | |
* $decoded = decode_query($url_query); | |
* | |
* -------------------------------------------------------- | |
* OUTPUT : | |
* | |
* Array | |
* ( | |
* [q] => lorem ipsum | |
* [orderby] => name | |
* [order] => desc | |
* ) | |
* --------------------------------------------------------- | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment