/** * Recursively cleans arrays, objects, and strings. Removes ASCII control * codes and converts to UTF-8 while silently discarding incompatible * UTF-8 characters. * * @param string string to clean * @return string */ public static function clean($str) { if (is_array($str) or is_object($str)) { foreach ($str as $key => $val) { // Recursion! $str[Input::clean($key)] = Input::clean($val); } } elseif (is_string($str) and $str !== '') { // Remove control characters $str = str::strip_ascii_ctrl($str); if (!str::is_ascii($str)) { // Disable notices $ER = error_reporting(~E_NOTICE); // iconv is expensive, so it is only used when needed $str = iconv(Eight::CHARSET, Eight::CHARSET . '//IGNORE', $str); // Turn notices back on error_reporting($ER); } } return $str; }