/** * Removes any invalid UTF-8 characters from a string or array of strings * * @param array|string $value The string or array of strings to clean * @return string The cleaned string */ public static function clean($value) { if (!is_array($value)) { if (self::$can_ignore_invalid === NULL) { self::$can_ignore_invalid = !in_array(strtolower(ICONV_IMPL), array('unknown', 'ibm iconv')); } fCore::startErrorCapture(E_NOTICE); $value = self::iconv('UTF-8', 'UTF-8' . (self::$can_ignore_invalid ? '//IGNORE' : ''), (string) $value); fCore::stopErrorCapture(); return $value; } $keys = array_keys($value); $num_keys = sizeof($keys); for ($i = 0; $i < $num_keys; $i++) { $value[$keys[$i]] = self::clean($value[$keys[$i]]); } return $value; }
/** * Removes any invalid UTF-8 characters from a string or array of strings * * @param array|string $value The string or array of strings to clean * @return string The cleaned string */ public static function clean($value) { if (!is_array($value)) { if (self::$can_ignore_invalid === NULL) { ob_start(); phpinfo(INFO_MODULES); $module_info = strip_tags(ob_get_contents()); ob_end_clean(); self::$can_ignore_invalid = !preg_match('#iconv\\s+implementation\\s+(=>\\s+)?unknown#ims', $module_info); } if (!self::$can_ignore_invalid) { $old_level = error_reporting(error_reporting() & ~E_NOTICE); } return iconv('UTF-8', 'UTF-8' . (self::$can_ignore_invalid ? '//IGNORE' : ''), (string) $value); if (!self::$can_ignore_invalid) { error_reporting($old_level); } } $keys = array_keys($value); $num_keys = sizeof($keys); for ($i = 0; $i < $num_keys; $i++) { $value[$keys[$i]] = self::clean($value[$keys[$i]]); } return $value; }
/** * Removes any invalid UTF-8 characters from a string or array of strings * * @param array|string $value The string or array of strings to clean * @return string The cleaned string */ public static function clean($value) { if (!is_array($value)) { self::checkMbString(); if (self::$mbstring_available) { $old_sub = ini_get('mbstring.substitute_character'); ini_set('mbstring.substitute_character', 'none'); $value = mb_convert_encoding($value, 'UTF-8', 'UTF-8'); ini_set('mbstring.substitute_character', $old_sub); return $value; } if (self::$can_ignore_invalid === NULL) { self::$can_ignore_invalid = !in_array(strtolower(ICONV_IMPL), array('unknown', 'ibm iconv')); } fCore::startErrorCapture(E_NOTICE); $value = self::iconv('UTF-8', 'UTF-8' . (self::$can_ignore_invalid ? '//IGNORE' : ''), (string) $value); fCore::stopErrorCapture(); return $value; } $keys = array_keys($value); $num_keys = sizeof($keys); for ($i = 0; $i < $num_keys; $i++) { $value[$keys[$i]] = self::clean($value[$keys[$i]]); } return $value; }