summaryrefslogtreecommitdiffstats
path: root/system/core/Input.php
diff options
context:
space:
mode:
authornisheeth-barthwal <nisheeth.barthwal@nbaztec.co.in>2013-03-25 19:12:36 +0100
committernisheeth-barthwal <nisheeth.barthwal@nbaztec.co.in>2013-03-25 19:12:36 +0100
commit77236e055234cbbc9f6ca6be472c70077a1f5856 (patch)
treeef91b1b78aa5bd4dac90737af0f8611f6a9bdbf2 /system/core/Input.php
parent7b1a2f1f40d940dde34e47b36808a84e0353af56 (diff)
Simplified notation parsing and other cosmetic fixes
Diffstat (limited to 'system/core/Input.php')
-rw-r--r--system/core/Input.php47
1 files changed, 16 insertions, 31 deletions
diff --git a/system/core/Input.php b/system/core/Input.php
index 6ee132005..d707fe25c 100644
--- a/system/core/Input.php
+++ b/system/core/Input.php
@@ -153,53 +153,38 @@ class CI_Input {
*/
protected function _fetch_from_array(&$array, $index = '', $xss_clean = FALSE)
{
- $value = NULL;
-
if (isset($array[$index]))
{
$value = $array[$index];
}
- elseif(preg_match('/\[[^]]*\]$/', $index)) // Does the index contain array notation
+ elseif (($count = preg_match_all('/(?:^[^\[]+)|\[[^]]*\]/', $index, $matches)) > 1) // Does the index contain array notation
{
- $key = $index;
$container = $array;
-
- // Test if the $index is an array name, and try to obtain the final index
- if (preg_match_all('/\[(.*?)\]/', $index, $matches))
+ for ($i = 0; $i < $count; $i++)
{
- sscanf($index, '%[^[][', $key);
- for ($i = 0, $c = count($matches[0]); $i < $c; $i++)
+ $key = trim($matches[0][$i], '[]');
+ if($key === '') // The array notation will return the value as array
{
- if($matches[1][$i] === '') // The array notation will return the value as array
- {
- break;
- }
- if (isset($container[$key]))
- {
- $container = $container[$key];
- $key = $matches[1][$i];
- }
- else
- {
- $container = array();
- break;
- }
+ break;
}
-
- // Check if the deepest container has the field
- if(isset($container[$key]))
+ if (isset($container[$key]))
+ {
+ $value = $container = $container[$key];
+ }
+ else
{
- $value = $container[$key];
+ return NULL;
}
}
}
-
- if ($xss_clean === TRUE)
+ else
{
- return $this->security->xss_clean($value);
+ return NULL;
}
- return $value;
+ return ($xss_clean === TRUE)
+ ? $this->security->xss_clean($value)
+ : $value;
}
// --------------------------------------------------------------------