1--TEST-- 2Test mb_encode_numericentity() function: Convert text to HTML entities 3--EXTENSIONS-- 4mbstring 5--FILE-- 6<?php 7$str1 = '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ'; 8$str2 = 'ƒΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρςστυφχψωϑϒϖ•…′″‾⁄℘ℑℜ™ℵ←↑→↓↔↵⇐⇑⇒⇓⇔∀∂∃∅∇∈∉∋∏∑−∗√∝∞∠∧∨∩∪∫∴∼≅≈≠≡≤≥⊂⊃⊄⊆⊇⊕⊗⊥⋅⌈⌉⌊⌋〈〉◊♠♣♥♦'; 9$convmap = array(0x0, 0x2FFFF, 0, 0xFFFF); 10echo "1: " . mb_encode_numericentity($str1, $convmap, "UTF-8") . "\n"; 11echo "1 (hex): " . mb_encode_numericentity($str1, $convmap, "UTF-8", true) . "\n"; 12echo "2: " . mb_encode_numericentity($str2, $convmap, "UTF-8") . "\n"; 13 14$convmap = array(0xFF, 0x2FFFF, 0, 0xFFFF); 15echo "3: " . mb_encode_numericentity('aŒbœcŠdše€fg', $convmap, "UTF-8") . "\n"; 16 17$convmap = []; 18echo "4: " . mb_encode_numericentity('föo', $convmap, "UTF-8") . "\n"; 19 20try { 21 $convmap = array(0xFF, 0x2FFFF, 0); // 3 elements 22 echo "5: " . mb_encode_numericentity('aŒbœcŠdše€fg', $convmap, "UTF-8") . "\n"; 23} catch (ValueError $ex) { 24 echo "5: " . $ex->getMessage() . "\n"; 25} 26 27// HTML-encode a null byte 28echo "6: " . mb_encode_numericentity("\x00", array(0, 1, 0, 0xFFFF), "UTF-8", false) . "\n"; 29echo "6 (hex): " . mb_encode_numericentity("\x00", array(0, 1, 0, 0xFFFF), "UTF-8", true) . "\n"; 30 31// Try doing weird things with convmap 32$convmap = [ 33 0, 0, 0, 0, // Only one codepoint, empty mask 34 100, 50, 0, 0xFFFF // 'End' codepoint is before 'start' codepoint 35]; 36echo "7: " . mb_encode_numericentity('föo', $convmap, "UTF-8") . "\n"; 37echo "7 (hex): " . mb_encode_numericentity('föo', $convmap, "UTF-8", true) . "\n"; 38 39// Try using positive offset 40$convmap = [0, 10, 1000, 0xFFFF]; 41echo "8: " . mb_encode_numericentity("\x01\x02\x03", $convmap, "UTF-8") . "\n"; 42echo "8 (hex): " . mb_encode_numericentity("\x01\x02\x03", $convmap, "UTF-8", true) . "\n"; 43 44// Try using negative offset 45$convmap = [0, 10, -100000, 0xFFFFFF]; 46echo "9: " . mb_encode_numericentity("\x01\x02\x03", $convmap, "UTF-8") . "\n"; 47echo "9 (hex): " . mb_encode_numericentity("\x01\x02\x03", $convmap, "UTF-8", true) . "\n"; 48 49// Try using mask to remove some bits 50$convmap = [0, 1000, 0, 0x123]; 51echo "10: " . mb_encode_numericentity('föo', $convmap, "UTF-8") . "\n"; 52echo "10 (hex): " . mb_encode_numericentity('föo', $convmap, "UTF-8", true) . "\n"; 53 54// Try different text encoding 55$convmap = [0, 0xFFFF, 0, 0xFFFF]; 56$iso2022jp = "\x1B\$B\x21\x21!r\x1B(BABC"; 57echo "11: " . mb_encode_numericentity($iso2022jp, $convmap, "ISO-2022-JP") . "\n"; 58echo "11 (hex): " . mb_encode_numericentity($iso2022jp, $convmap, "ISO-2022-JP", true) . "\n"; 59 60// Regression test; the old implementation could only emit decimal entities with about 7 digits 61$convmap = [0x2b, 0x2d4, 0x75656500, 0x656d2c53]; 62echo "12: " . mb_encode_numericentity("m", $convmap, "ASCII") . "\n"; 63 64// Regression test; the old implementation could only emit hexadecimal entities with about 5 digits 65$convmap = [0xffffffff, 0xffffffff, 0x540a0af7, 0x5a485054]; 66echo "13: " . mb_encode_numericentity("\xFF", $convmap, "ASCII", true) . "\n"; 67 68?> 69--EXPECT-- 701: ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ 711 (hex): ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ 722: ƒΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρςστυφχψωϑϒϖ•…′″‾⁄℘ℑℜ™ℵ←↑→↓↔↵⇐⇑⇒⇓⇔∀∂∃∅∇∈∉∋∏∑−∗√∝∞∠∧∨∩∪∫∴∼≅≈≠≡≤≥⊂⊃⊄⊆⊇⊕⊗⊥⋅⌈⌉⌊⌋〈〉◊♠♣♥♦ 733: aŒbœcŠdše€fg 744: föo 755: mb_encode_numericentity(): Argument #2 ($map) must have a multiple of 4 elements 766: � 776 (hex): � 787: föo 797 (hex): föo 808: ϩϪϫ 818 (hex): ϩϪϫ 829: ��� 839 (hex): ��� 8410: ""# 8510 (hex): ""# 8611:  £ABC 8711 (hex):  £ABC 8812: � 8913: � 90