Created
May 30, 2011 22:20
-
-
Save dragoonis/999568 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Obtain a url segments value pair by specifying the key. | |
* eg: /key/val/key2/val2 - by specifying key, you get val, by specifying key2, you get val2. | |
* @param string $p_sIndex The specified key | |
* @param string $p_sDefaultValue The default value to return in the situation that the key or subsequent value was not found. | |
* @return mixed (Can be user defined) | |
*/ | |
function get($p_sIndex, $p_sDefaultValue = "") { | |
$tmp = array(); | |
$count = count($this->_uriParams); | |
for($i = 0 , $j = 1; $i < $count; $i+=1, $j++) { | |
if(!empty($this->_uriParams[$i]) && isset($this->_uriParams[$j])) { | |
if(is_integer($this->_uriParams[$j]) || $this->_uriParams[$j] == '0') { | |
$tmp[$this->_uriParams[$i]] = (int) $this->_uriParams[$j]; | |
} else { | |
$tmp[$this->_uriParams[$i]] = $this->_uriParams[$j]; | |
} | |
} else { | |
$tmp[$this->_uriParams[$i]] = ''; | |
} | |
} | |
if(!empty($tmp)) { | |
foreach($tmp as $item => $val) { | |
if($item == $p_sIndex) { | |
if(is_integer ($val) OR $val == '0') { | |
return (int) $val; | |
} elseif(!empty($val)) { | |
return urldecode ($val); | |
} | |
} | |
} | |
} | |
if(empty($p_sDefaultValue)) $p_sDefaultValue = ""; | |
if(isset($_GET[$p_sIndex])) { | |
if(is_integer ($_GET[$p_sIndex]) || $_GET[$p_sIndex] == '0') { | |
return (int) $_GET[$p_sIndex]; | |
} | |
return (!empty($_GET[$p_sIndex])) ? urldecode($_GET[$p_sIndex]) : urldecode($p_sDefaultValue); | |
} | |
return urldecode($p_sDefaultValue); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment