Kohana Patch: Input library problem with [ and ]


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /**
  2.  * Fetch an item from a global array.
  3.  *
  4.  * @param array array to search
  5.  * @param string key to find
  6.  * @param mixed default value
  7.  * @param boolean XSS clean the value
  8.  * @return mixed
  9.  */
  10. protected function search_array($array, $key, $default = NULL, $xss_clean = FALSE)
  11. {
  12. if ($key === array())
  13. return $array;
  14.  
  15. //$key = 'option[min][max][x]';
  16.  
  17. // patch: start
  18. if (preg_match_all('!(?:\[([^]]+)\])!', $key, $subkeys))
  19. {
  20. list(, $subkeys) = $subkeys;
  21. array_unshift($subkeys, substr($key, 0, strpos($key, '[')));
  22. foreach ($subkeys as $key)
  23. {
  24. if ( ! isset($array[$key]))
  25. return $default;
  26. $array = $array[$key];
  27. }
  28. return $array;
  29. }
  30. // end
  31.  
  32. if ( ! isset($array[$key]))
  33. return $default;
  34.  
  35. // Get the value
  36. $value = $array[$key];
  37.  
  38. if ($this->use_xss_clean === FALSE AND $xss_clean === TRUE)
  39. {
  40. // XSS clean the value
  41. $value = $this->xss_clean($value);
  42. }
  43.  
  44. return $value;
  45. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.