W3cubDocs

/Drupal 8

protected static function PhpTransliteration::ordUTF8

protected static PhpTransliteration::ordUTF8($character)

Finds the character code for a UTF-8 character: like ord() but for UTF-8.

Parameters

string $character: A single UTF-8 character.

Return value

int The character code, or -1 if an illegal character is found.

File

core/lib/Drupal/Component/Transliteration/PhpTransliteration.php, line 144

Class

PhpTransliteration
Implements transliteration without using the PECL extensions.

Namespace

Drupal\Component\Transliteration

Code

protected static function ordUTF8($character) {
  $first_byte = ord($character[0]);

  if (($first_byte & 0x80) == 0) {
    // Single-byte form: 0xxxxxxxx.
    return $first_byte;
  }
  if (($first_byte & 0xe0) == 0xc0) {
    // Two-byte form: 110xxxxx 10xxxxxx.
    return (($first_byte & 0x1f) << 6) + (ord($character[1]) & 0x3f);
  }
  if (($first_byte & 0xf0) == 0xe0) {
    // Three-byte form: 1110xxxx 10xxxxxx 10xxxxxx.
    return (($first_byte & 0x0f) << 12) + ((ord($character[1]) & 0x3f) << 6) + (ord($character[2]) & 0x3f);
  }
  if (($first_byte & 0xf8) == 0xf0) {
    // Four-byte form: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx.
    return (($first_byte & 0x07) << 18) + ((ord($character[1]) & 0x3f) << 12) + ((ord($character[2]) & 0x3f) << 6) + (ord($character[3]) & 0x3f);
  }

  // Other forms are not legal.
  return -1;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Component!Transliteration!PhpTransliteration.php/function/PhpTransliteration::ordUTF8/8.1.x