Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function utf8_to_escaped_sjis($str) {
- $utf8 = preg_split('//u', $str, -1, PREG_SPLIT_NO_EMPTY);
- $sjis = $utf8;
- mb_convert_variables('SJIS', 'UTF-8', $sjis);
- $table = get_html_translation_table(HTML_SPECIALCHARS | ENT_QUOTES);
- foreach ($sjis as $i => &$char) {
- if ($char === '?' && $utf8[$i] !== '?') {
- $char = mb_convert_encoding($utf8[$i], 'HTML-ENTITIES', 'UTF-8');
- } elseif (isset($table[$char])) {
- $char = $table[$char];
- }
- }
- return implode('', $sjis);
- }
Advertisement
Add Comment
Please, Sign In to add comment