2 namespace Masterminds\HTML5\Parser;
4 use Masterminds\HTML5\Entities;
7 * Manage entity references.
9 * This is a simple resolver for HTML5 character reference entitites.
10 * See \Masterminds\HTML5\Entities for the list of supported entities.
12 class CharacterReference
15 protected static $numeric_mask = array(
24 * 'amp'), lookup the UTF-8 character ('&')
27 * The name to look up.
28 * @return string The character sequence. In UTF-8 this may be more than one byte.
30 public static function lookupName($name)
32 // Do we really want to return NULL here? or FFFD
33 return isset(Entities::$byName[$name]) ? Entities::$byName[$name] : null;
37 * Given a Unicode codepoint, return the UTF-8 character.
42 * public static function lookupCode($codePoint) { return 'POINT'; }
46 * Given a decimal number, return the UTF-8 character.
48 public static function lookupDecimal($int)
50 $entity = '&#' . $int . ';';
51 // UNTESTED: This may fail on some planes. Couldn't find full documentation
52 // on the value of the mask array.
53 return mb_decode_numericentity($entity, static::$numeric_mask, 'utf-8');
57 * Given a hexidecimal number, return the UTF-8 character.
59 public static function lookupHex($hexdec)
61 return static::lookupDecimal(hexdec($hexdec));