Esempio n. 1
0
 /**
  * get all codepoints of a string
  */
 public static function parseString($string, $db)
 {
     $cps = [];
     if (mb_strlen($string) < self::PARSE_STRING_MAXLENGTH) {
         foreach (preg_split('/(?<!^)(?!$)/u', $string) as $c) {
             $cc = unpack('N', mb_convert_encoding($c, 'UCS-4BE', 'UTF-8'));
             try {
                 $cx = Codepoint::getCP($cc[1], $db);
                 // test, if codepoint exists
                 $cx->getName();
                 $cps[] = $cx;
             } catch (Exception $e) {
             }
         }
     }
     return $cps;
 }
Esempio n. 2
0
 /**
  * get the names of all characters in the set
  */
 protected function fetchNames($set)
 {
     $this->sanitizeSet($set);
     $names = [];
     if (count($set) > 0) {
         $query = $this->db->prepare("\n              SELECT cp, na, na1, (SELECT codepoint_image.image\n                                     FROM codepoint_image\n                                    WHERE codepoint_image.cp = codepoints.cp) image\n                FROM codepoints\n               WHERE cp IN (" . join(',', $set) . ")");
         $query->execute();
         $r = $query->fetchAll(\PDO::FETCH_ASSOC);
         $query->closeCursor();
         if ($r !== False) {
             foreach ($r as $cp) {
                 if (!$cp['image']) {
                     $cp['image'] = '';
                 }
                 $names[intval($cp['cp'])] = Codepoint::getCP(intval($cp['cp']), $this->db, ['name' => $cp['na'] ? $cp['na'] : ($cp['na1'] ? $cp['na1'] . '*' : '<control>'), 'block' => $this, 'image' => 'data:image/png;base64,' . $cp['image']]);
             }
         }
     }
     return $names;
 }