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 20// HTML-encode a null byte 21echo "6: " . mb_encode_numericentity("\x00", array(0, 1, 0, 0xFFFF), "UTF-8", false) . "\n"; 22echo "6 (hex): " . mb_encode_numericentity("\x00", array(0, 1, 0, 0xFFFF), "UTF-8", true) . "\n"; 23 24// Try doing weird things with convmap 25$convmap = [ 26 0, 0, 0, 0, // Only one codepoint, empty mask 27 100, 50, 0, 0xFFFF // 'End' codepoint is before 'start' codepoint 28]; 29echo "7: " . mb_encode_numericentity('föo', $convmap, "UTF-8") . "\n"; 30echo "7 (hex): " . mb_encode_numericentity('föo', $convmap, "UTF-8", true) . "\n"; 31 32// Try using positive offset 33$convmap = [0, 10, 1000, 0xFFFF]; 34echo "8: " . mb_encode_numericentity("\x01\x02\x03", $convmap, "UTF-8") . "\n"; 35echo "8 (hex): " . mb_encode_numericentity("\x01\x02\x03", $convmap, "UTF-8", true) . "\n"; 36 37// Try using negative offset 38$convmap = [0, 10, -100000, 0xFFFFFF]; 39echo "9: " . mb_encode_numericentity("\x01\x02\x03", $convmap, "UTF-8") . "\n"; 40echo "9 (hex): " . mb_encode_numericentity("\x01\x02\x03", $convmap, "UTF-8", true) . "\n"; 41 42// Try using mask to remove some bits 43$convmap = [0, 1000, 0, 0x123]; 44echo "10: " . mb_encode_numericentity('föo', $convmap, "UTF-8") . "\n"; 45echo "10 (hex): " . mb_encode_numericentity('föo', $convmap, "UTF-8", true) . "\n"; 46 47// Try different text encoding 48$convmap = [0, 0xFFFF, 0, 0xFFFF]; 49$iso2022jp = "\x1B\$B\x21\x21!r\x1B(BABC"; 50echo "11: " . mb_encode_numericentity($iso2022jp, $convmap, "ISO-2022-JP") . "\n"; 51echo "11 (hex): " . mb_encode_numericentity($iso2022jp, $convmap, "ISO-2022-JP", true) . "\n"; 52 53// Regression test; the old implementation could only emit decimal entities with about 7 digits 54$convmap = [0x2b, 0x2d4, 0x75656500, 0x656d2c53]; 55echo "12: " . mb_encode_numericentity("m", $convmap, "ASCII") . "\n"; 56 57?> 58--EXPECT-- 591: ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ 601 (hex): ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ 612: ƒΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρςστυφχψωϑϒϖ•…′″‾⁄℘ℑℜ™ℵ←↑→↓↔↵⇐⇑⇒⇓⇔∀∂∃∅∇∈∉∋∏∑−∗√∝∞∠∧∨∩∪∫∴∼≅≈≠≡≤≥⊂⊃⊄⊆⊇⊕⊗⊥⋅⌈⌉⌊⌋〈〉◊♠♣♥♦ 623: aŒbœcŠdše€fg 634: föo 646: � 656 (hex): � 667: föo 677 (hex): föo 688: ϩϪϫ 698 (hex): ϩϪϫ 709: ��� 719 (hex): ��� 7210: ""# 7310 (hex): ""# 7411:  £ABC 7511 (hex):  £ABC 7612: � 77