function String_::codePointToUtf8
Converts a Unicode code point to its UTF-8 encoded representation.
Parameters
int $num Code point:
Return value
string UTF-8 representation of code point
1 call to String_::codePointToUtf8()
- String_::parseEscapeSequences in vendor/
nikic/ php-parser/ lib/ PhpParser/ Node/ Scalar/ String_.php - @internal
File
-
vendor/
nikic/ php-parser/ lib/ PhpParser/ Node/ Scalar/ String_.php, line 141
Class
Namespace
PhpParser\Node\ScalarCode
private static function codePointToUtf8(int $num) : string {
if ($num <= 0x7f) {
return chr($num);
}
if ($num <= 0x7ff) {
return chr(($num >> 6) + 0xc0) . chr(($num & 0x3f) + 0x80);
}
if ($num <= 0xffff) {
return chr(($num >> 12) + 0xe0) . chr(($num >> 6 & 0x3f) + 0x80) . chr(($num & 0x3f) + 0x80);
}
if ($num <= 0x1fffff) {
return chr(($num >> 18) + 0xf0) . chr(($num >> 12 & 0x3f) + 0x80) . chr(($num >> 6 & 0x3f) + 0x80) . chr(($num & 0x3f) + 0x80);
}
throw new Error('Invalid UTF-8 codepoint escape sequence: Codepoint too large');
}