3 namespace RemexHtml\DOM;
4 use RemexHtml\HTMLData;
8 * Replace unsupported characters with a code of the form U123456.
13 public static function coerceName( $name ) {
15 mb_encode_numericentity( mb_substr( $name, 0, 1, 'UTF-8' ),
16 HTMLData::$nameStartCharConvTable, 'UTF-8', true ) .
17 mb_encode_numericentity( mb_substr( $name, 1, null, 'UTF-8' ),
18 HTMLData::$nameCharConvTable, 'UTF-8', true );
19 $coercedName = preg_replace_callback( '/&#x([0-9A-F]*);/',
21 return 'U' . str_pad( $m[1], 6, '0', STR_PAD_LEFT );
28 * Invert the encoding produced by coerceName()
33 public static function uncoerceName( $name ) {
34 return mb_decode_numericentity(
35 preg_replace( '/U([0-9A-F]{6})/', '&#x\1;', $name ),
36 [ 0, 0x10ffff, 0, 0xffffff ],