is_ascii($str) === false) { if (MB_ENABLED) { $str = mb_convert_encoding($str, 'UTF-8', 'UTF-8'); } elseif (ICONV_ENABLED) { $str = @iconv('UTF-8', 'UTF-8//IGNORE', $str); } } return $str; } // -------------------------------------------------------------------- /** * Remove ASCII control characters * * Removes all ASCII control characters except horizontal tabs, * line feeds, and carriage returns, as all others can cause * problems in XML. * * @param string $str String to clean * @return string */ public function safe_ascii_for_xml($str) { return remove_invisible_characters($str, false); } // -------------------------------------------------------------------- /** * Convert to UTF-8 * * Attempts to convert a string to UTF-8. * * @param string $str Input string * @param string $encoding Input encoding * @return string $str encoded in UTF-8 or FALSE on failure */ public function convert_to_utf8($str, $encoding) { if (MB_ENABLED) { return mb_convert_encoding($str, 'UTF-8', $encoding); } elseif (ICONV_ENABLED) { return @iconv($encoding, 'UTF-8', $str); } return false; } // -------------------------------------------------------------------- /** * Is ASCII? * * Tests if a string is standard 7-bit ASCII or not. * * @param string $str String to check * @return bool */ public function is_ascii($str) { return (preg_match('/[^\x00-\x7F]/S', $str) === 0); } }