ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
CharacterConvert.php
Go to the documentation of this file.
1 <?php
2 
4 
7 
9 {
15  public static function character($character): string
16  {
17  $character = Functions::flattenSingleValue($character);
18 
19  if (!is_numeric($character)) {
20  return Functions::VALUE();
21  }
22 
23  $character = (int) $character;
24  if ($character < 1 || $character > 255) {
25  return Functions::VALUE();
26  }
27 
28  return iconv('UCS-4LE', 'UTF-8', pack('V', $character));
29  }
30 
38  public static function code($characters)
39  {
40  if (($characters === null) || ($characters === '')) {
41  return Functions::VALUE();
42  }
43  $characters = Functions::flattenSingleValue($characters);
44  if (is_bool($characters)) {
45  $characters = self::convertBooleanValue($characters);
46  }
47 
48  $character = $characters;
49  if (mb_strlen($characters, 'UTF-8') > 1) {
50  $character = mb_substr($characters, 0, 1, 'UTF-8');
51  }
52 
53  return self::unicodeToOrd($character);
54  }
55 
56  private static function unicodeToOrd($character)
57  {
58  return unpack('V', iconv('UTF-8', 'UCS-4LE', $character))[1];
59  }
60 
61  private static function convertBooleanValue($value)
62  {
64  return (int) $value;
65  }
66 
67  return ($value) ? Calculation::getTRUE() : Calculation::getFALSE();
68  }
69 }
static getFALSE()
Return the locale-specific translation of FALSE.
static getTRUE()
Return the locale-specific translation of TRUE.
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.
Definition: Functions.php:649
static getCompatibilityMode()
Return the current Compatibility Mode.
Definition: Functions.php:93