- Output for 5.4.2 - 5.4.45, 5.5.24 - 5.5.30, 5.6.7 - 5.6.14
- Parse error: syntax error, unexpected 'public' (T_PUBLIC) in /in/KhqTU on line 8
Process exited with code 255.
<?php
$unko = "\xf0\x9f\x92\xa9";
$cesu = $this->convert_char_to_cesu8($unko);
var_dump($cesu);
$encode = json_encode($unko);
public function convert_char_to_cesu8($utf8_char) {
if (strlen($utf8_char) < 3) {
return $utf8_char;
}
$s = mb_convert_encoding($utf8_char, 'UTF-16BE', 'UTF-8');
// UTF-16BEは 110110ww wwxxxxxx 110111xx xxxxxxxx
// これを 11101101 1010wwww 10xxxxxx 11101101 1011xxxx 10xxxxxx にする
$w1 = ord($s[0]) & 0b00000011;
$w2 = ord($s[1]) & 0b11000000;
$x1 = ord($s[1]) & 0b00111111;
$x2 = ord($s[2]) & 0b00000011;
$x3 = ord($s[3]);
return
chr(0b11101101) .
chr(0b10100000 | $w1 << 2 | $w2 >> 6) .
chr(0b10000000 | $x1) .
chr(0b11101101) .
chr(0b10110000 | $x2 << 2 | $x3 >> 6) .
chr(0b10000000 | ($x3 & 0b00111111));
}