y s ƌ ” µ છ x ‘ Ε Μ Ƭ
Unchanged: y s ƌ µ છ x Ε Μ Ƭ
Codepoints: 121 115 396 8221 181 2715 120 8216 917 924 428
In utf-8
: y s ƌ ” µ છ x ‘ Ε Μ Ƭ
Highlighted with my highlighter.
<?php
function
stringToCodePoints
($str) { $str=
fixCharacters
($str); $str=
preg_replace_callback
('/&#([0-9]+);/'
,create_function
('$s'
,'return $s[1];'
), $str ); $str=
preg_replace_callback
('/&#x([a-f0-9]+);/i'
,create_function
('$s'
,'return hexdec($s[1]);'
), $str );return
$str; }function
stringToUtf8
($str) { $str=
fixCharacters
($str); $str=
preg_replace_callback
('/&#([0-9]+);/'
,create_function
('$s'
,'return code2utf($s[1]);'
), $str ); $str=
preg_replace_callback
('/&#x([a-f0-9]+);/i'
,create_function
('$s'
,'return code2utf(hexdec($s[1]));'
), $str );return
$str; }function
fixCharacters
($str) { $r=
array
('€'
=>
'€'
,''
=>
''
,'‚'
=>
'‚'
,'ƒ'
=>
'ƒ'
,'„'
=>
'„'
,'…'
=>
'…'
,'†'
=>
'†'
,'‡'
=>
'‡'
,'ˆ'
=>
'ˆ'
,'‰'
=>
'‰'
,'Š'
=>
'Š'
,'‹'
=>
'‹'
,'Œ'
=>
'Œ'
,''
=>
''
,'Ž'
=>
'Ž'
,''
=>
''
,''
=>
''
,'‘'
=>
'‘'
,'’'
=>
'’'
,'“'
=>
'“'
,'”'
=>
'”'
,'•'
=>
'•'
,'–'
=>
'–'
,'—'
=>
'—'
,'˜'
=>
'˜'
,'™'
=>
'™'
,'š'
=>
'š'
,'›'
=>
'›'
,'œ'
=>
'œ'
,''
=>
''
,'ž'
=>
'ž'
,'Ÿ'
=>
'Ÿ'
);return
strtr
($str, $r); }// From php.net:
function
code2utf
($num){if
($num<
128
) {return
chr
($num); }if
($num<
2048
) {return
chr
(($num>>
6
)+
192
) .chr
(($num &63
)+
128
); }if
($num<
65536
) {return
chr
(($num>>
12
)+
224
) .chr
((($num>>
6
) &63
)+
128
) .chr
(($num &63
)+
128
); }if
($num<
2097152
) {return
chr
(($num>>
18
)+
240
) .chr
((($num>>
12
) &63
)+
128
) .chr
((($num>>
6
) &63
)+
128
) .chr
(($num &63
)+
128
); }return
''
; }?>