Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Utils.php

function Utils::unicodeToUtf8

Converts an unicode code point to UTF-8

@codeCoverageIgnore

Parameters

int $num Unicode code point:

Return value

string

6 calls to Utils::unicodeToUtf8()
Identifier::setRawName in vendor/mck89/peast/lib/Peast/Syntax/Node/Identifier.php
Sets the identifier's raw name
Scanner::consumeUnicodeEscapeSequence in vendor/mck89/peast/lib/Peast/Syntax/Scanner.php
Consumes an unicode escape sequence
Scanner::__construct in vendor/mck89/peast/lib/Peast/Syntax/Scanner.php
Class constructor
Utils::getLineTerminators in vendor/mck89/peast/lib/Peast/Syntax/Utils.php
Returns line terminators array
Utils::surrogatePairToUtf8 in vendor/mck89/peast/lib/Peast/Syntax/Utils.php
Converts a surrogate pair of Unicode code points to UTF-8

... See full list

File

vendor/mck89/peast/lib/Peast/Syntax/Utils.php, line 58

Class

Utils
Utilities class.

Namespace

Peast\Syntax

Code

public static function unicodeToUtf8($num) {
    
    //From: http://stackoverflow.com/questions/1805802/php-convert-unicode-codepoint-to-utf-8#answer-7153133
    if ($num <= 0x7f) {
        return chr($num);
    }
    elseif ($num <= 0x7ff) {
        return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
    }
    elseif ($num <= 0xffff) {
        return chr(($num >> 12) + 224) . chr(($num >> 6 & 63) + 128) . chr(($num & 63) + 128);
    }
    elseif ($num <= 0x1fffff) {
        return chr(($num >> 18) + 240) . chr(($num >> 12 & 63) + 128) . chr(($num >> 6 & 63) + 128) . chr(($num & 63) + 128);
    }
    return '';
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal