3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function filter_input_utf8($type, $default = array()) { static $is_recursive_static = false; $is_recursive = $is_recursive_static; if (!$is_recursive_static) { $types = array( INPUT_GET => $_GET, INPUT_POST => $_POST, INPUT_COOKIE => $_COOKIE, INPUT_REQUEST => $_REQUEST, INPUT_ENV => $_ENV, INPUT_SERVER => $_SERVER, ); if (!isset($types[$type])) { return $default; } $var = $types[$type]; $is_recursive_static = true; } else { $var = $type; } $ret = array(); foreach ((array)$default as $key => $value) { if (!isset($var[$key])) { $ret[$key] = $value; } elseif (is_array($value)) { $ret[$key] = filter_input_utf8($var[$key], $value); } elseif (is_array($var[$key]) || !preg_match('//u', $var)) { $ret[$key] = $value; } else { $ret[$key] = $var[$key]; } } if (!$is_recursive) { $is_recursive_static = false; } return $ret; } $_POST = array( 'a' => array( 'b' => 'Invalid Data', ), 'c' => array( 'd' => 'Valid Data', ), 'e' => 'Valid Data', 'f' => 'Unneeded Data', ); $post = filter_input_utf8($_POST, array( 'a' => null, 'c' => array( 'd' => null, ), 'e' => null, )); var_dump($post);
Output for 5.2.0 - 7.1.0
Warning: Illegal offset type in isset or empty in /in/9g2pR on line 14 array(3) { ["a"]=> NULL ["c"]=> array(1) { ["d"]=> NULL } ["e"]=> NULL }
Output for 5.1.0 - 5.1.6
Notice: Use of undefined constant INPUT_GET - assumed 'INPUT_GET' in /in/9g2pR on line 7 Notice: Use of undefined constant INPUT_POST - assumed 'INPUT_POST' in /in/9g2pR on line 8 Notice: Use of undefined constant INPUT_COOKIE - assumed 'INPUT_COOKIE' in /in/9g2pR on line 9 Notice: Use of undefined constant INPUT_REQUEST - assumed 'INPUT_REQUEST' in /in/9g2pR on line 10 Notice: Use of undefined constant INPUT_ENV - assumed 'INPUT_ENV' in /in/9g2pR on line 11 Notice: Use of undefined constant INPUT_SERVER - assumed 'INPUT_SERVER' in /in/9g2pR on line 12 Warning: Illegal offset type in isset or empty in /in/9g2pR on line 14 array(3) { ["a"]=> NULL ["c"]=> array(1) { ["d"]=> NULL } ["e"]=> NULL }
Output for 5.0.0 - 5.0.5
Notice: Use of undefined constant INPUT_GET - assumed 'INPUT_GET' in /in/9g2pR on line 7 Notice: Use of undefined constant INPUT_POST - assumed 'INPUT_POST' in /in/9g2pR on line 8 Notice: Use of undefined constant INPUT_COOKIE - assumed 'INPUT_COOKIE' in /in/9g2pR on line 9 Notice: Use of undefined constant INPUT_REQUEST - assumed 'INPUT_REQUEST' in /in/9g2pR on line 10 Notice: Use of undefined constant INPUT_ENV - assumed 'INPUT_ENV' in /in/9g2pR on line 11 Notice: Use of undefined constant INPUT_SERVER - assumed 'INPUT_SERVER' in /in/9g2pR on line 12 Warning: Illegal offset type in unset in /in/9g2pR on line 14 array(3) { ["a"]=> NULL ["c"]=> array(1) { ["d"]=> NULL } ["e"]=> NULL }
Output for 4.3.0 - 4.4.9
Notice: Use of undefined constant INPUT_GET - assumed 'INPUT_GET' in /in/9g2pR on line 7 Notice: Use of undefined constant INPUT_POST - assumed 'INPUT_POST' in /in/9g2pR on line 8 Notice: Use of undefined constant INPUT_COOKIE - assumed 'INPUT_COOKIE' in /in/9g2pR on line 9 Notice: Use of undefined constant INPUT_REQUEST - assumed 'INPUT_REQUEST' in /in/9g2pR on line 10 Notice: Use of undefined constant INPUT_ENV - assumed 'INPUT_ENV' in /in/9g2pR on line 11 Notice: Use of undefined constant INPUT_SERVER - assumed 'INPUT_SERVER' in /in/9g2pR on line 12 Warning: Illegal offset type in /in/9g2pR on line 14 array(3) { ["a"]=> NULL ["c"]=> array(1) { ["d"]=> NULL } ["e"]=> NULL }