Created
April 7, 2013 20:11
-
-
Save swvitaliy/5332279 to your computer and use it in GitHub Desktop.
Функция. Возвращает значение гет параметра из урла или указанное в 3м параметре дефолтное значение.
This file contains hidden or 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 | |
/** | |
* Возвращает значение гет параметра из урла или указанное в 3м параметре дефолтное значение. | |
* | |
* Example: url_get_arg('http://test.ru/test/?a=6&b=533&c=100', 'c', NULL); | |
*/ | |
function url_get_arg($url, $name, $default = NULL) { | |
$q_pos = strpos($url, '?'); | |
if ($q_pos === FALSE) { | |
return $default; | |
} | |
$get_args = substr($url, $q_pos + 1); | |
$get_args = explode('&', $get_args); | |
$kw_args = array(); | |
foreach($get_args as $v) { | |
$eq_pos = strpos($v, '='); | |
if ($eq_pos === FALSE) { | |
$kw_args[$v] = ''; | |
} else { | |
$kw_args[substr($v, 0, $eq_pos)] = substr($v, $eq_pos + 1); | |
} | |
} | |
return isset($kw_args[$name]) ? $kw_args[$name] : $default; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment