| | |
| | | return utf8_encode($str); |
| | | } |
| | | else { |
| | | user_error("No suitable function found for UTF-8 encoding", E_USER_WARNING); |
| | | trigger_error("No suitable function found for UTF-8 encoding"); |
| | | } |
| | | } |
| | | |
| | |
| | | return utf8_decode($str); |
| | | } |
| | | else { |
| | | user_error("No suitable function found for UTF-8 decoding", E_USER_WARNING); |
| | | trigger_error("No suitable function found for UTF-8 decoding"); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | // iconv/mbstring are much faster (especially with long strings) |
| | | if (function_exists('mb_convert_encoding')) { |
| | | $msch = mb_substitute_character('none'); |
| | | $msch = mb_substitute_character(); |
| | | mb_substitute_character('none'); |
| | | $res = mb_convert_encoding($input, 'UTF-8', 'UTF-8'); |
| | | mb_substitute_character($msch); |
| | |
| | | |
| | | // 1-byte character |
| | | if ($ord <= 0x7F) { |
| | | if ($seq) { |
| | | if ($seq !== '') { |
| | | $out .= preg_match($regexp, $seq) ? $seq : ''; |
| | | $seq = ''; |
| | | } |
| | | $seq = ''; |
| | | |
| | | $out .= $chr; |
| | | } |
| | | // first (or second) byte of multibyte sequence |
| | | // first byte of multibyte sequence |
| | | else if ($ord >= 0xC0) { |
| | | if (strlen($seq) > 1) { |
| | | if ($seq !== '') { |
| | | $out .= preg_match($regexp, $seq) ? $seq : ''; |
| | | $seq = ''; |
| | | } |
| | | else if ($seq && ord($seq) < 0xC0) { |
| | | $seq = ''; |
| | | } |
| | | $seq .= $chr; |
| | | |
| | | $seq = $chr; |
| | | } |
| | | // next byte of multibyte sequence |
| | | else if ($seq) { |
| | | else if ($seq !== '') { |
| | | $seq .= $chr; |
| | | } |
| | | } |
| | | |
| | | if ($seq) { |
| | | if ($seq !== '') { |
| | | $out .= preg_match($regexp, $seq) ? $seq : ''; |
| | | } |
| | | |