1--TEST-- 2Test htmlentities() function 3--FILE-- 4<?php 5/* Prototype: string htmlentities ( string $string [, int $quote_style [, string $charset]] ); 6 Description: Convert all applicable characters to HTML entities 7*/ 8 9/* retrieving htmlentities from the ANSI character table */ 10echo "*** Retrieving htmlentities for 256 characters ***\n"; 11for($i=0; $i<256; $i++) 12 var_dump( bin2hex( htmlentities(b"chr($i)")) ); 13 14/* giving arguments as NULL */ 15echo "\n*** Testing htmlentities() with NULL as first,second and third argument ***\n"; 16var_dump( htmlentities("\x82\x86\x99\x9f\x80\x82\x81", NULL, 'cp1252') ); 17var_dump( htmlentities("\x82\x86\x99\x9f\x80\x82\x81", ENT_QUOTES, NULL) ); /* UTF-8 assumed */ 18var_dump( htmlentities("\x82\x86\x99\x9f\x80\x82\x81", ENT_NOQUOTES, NULL) ); /* UTF-8 assumed */ 19var_dump( htmlentities("\x82\x86\x99\x9f\x80\x82\x81", ENT_COMPAT, NULL) ); /* UTF-8 assumed */ 20var_dump( htmlentities(NULL, NULL, NULL) ); 21 22/* giving long string to check for proper memory re-allocation */ 23echo "\n*** Checking for proper memory allocation with long string ***\n"; 24var_dump( htmlentities("\x82\x86\x99\x9f\x80\x82\x86\x84\x80\x89\x85\x83\x86\x84\x80\x91\x83\x91\x86\x87\x85\x86\x88\x82\x89\x92\x91\x83", ENT_QUOTES, 'cp1252')); 25 26/* giving a normal string */ 27echo "\n*** Testing a normal string with htmlentities() ***\n"; 28var_dump( htmlentities("<html> This is a test! </html>") ); 29 30/* checking behavior of quote */ 31echo "\n*** Testing htmlentites() on a quote ***\n"; 32$str = "A 'quote' is <b>bold</b>"; 33var_dump( htmlentities($str) ); 34var_dump( htmlentities($str, ENT_QUOTES) ); 35var_dump( htmlentities($str, ENT_NOQUOTES) ); 36var_dump( htmlentities($str, ENT_COMPAT) ); 37 38echo "\n*** Testing error conditions ***\n"; 39/* zero argument */ 40var_dump( htmlentities() ); 41/* arguments more than expected */ 42var_dump( htmlentities("\x84\x91",ENT_QUOTES, 'cp1252', "test1") ); 43 44echo "Done\n"; 45?> 46--EXPECTF-- 47*** Retrieving htmlentities for 256 characters *** 48string(12) "636872283029" 49string(12) "636872283129" 50string(12) "636872283229" 51string(12) "636872283329" 52string(12) "636872283429" 53string(12) "636872283529" 54string(12) "636872283629" 55string(12) "636872283729" 56string(12) "636872283829" 57string(12) "636872283929" 58string(14) "63687228313029" 59string(14) "63687228313129" 60string(14) "63687228313229" 61string(14) "63687228313329" 62string(14) "63687228313429" 63string(14) "63687228313529" 64string(14) "63687228313629" 65string(14) "63687228313729" 66string(14) "63687228313829" 67string(14) "63687228313929" 68string(14) "63687228323029" 69string(14) "63687228323129" 70string(14) "63687228323229" 71string(14) "63687228323329" 72string(14) "63687228323429" 73string(14) "63687228323529" 74string(14) "63687228323629" 75string(14) "63687228323729" 76string(14) "63687228323829" 77string(14) "63687228323929" 78string(14) "63687228333029" 79string(14) "63687228333129" 80string(14) "63687228333229" 81string(14) "63687228333329" 82string(14) "63687228333429" 83string(14) "63687228333529" 84string(14) "63687228333629" 85string(14) "63687228333729" 86string(14) "63687228333829" 87string(14) "63687228333929" 88string(14) "63687228343029" 89string(14) "63687228343129" 90string(14) "63687228343229" 91string(14) "63687228343329" 92string(14) "63687228343429" 93string(14) "63687228343529" 94string(14) "63687228343629" 95string(14) "63687228343729" 96string(14) "63687228343829" 97string(14) "63687228343929" 98string(14) "63687228353029" 99string(14) "63687228353129" 100string(14) "63687228353229" 101string(14) "63687228353329" 102string(14) "63687228353429" 103string(14) "63687228353529" 104string(14) "63687228353629" 105string(14) "63687228353729" 106string(14) "63687228353829" 107string(14) "63687228353929" 108string(14) "63687228363029" 109string(14) "63687228363129" 110string(14) "63687228363229" 111string(14) "63687228363329" 112string(14) "63687228363429" 113string(14) "63687228363529" 114string(14) "63687228363629" 115string(14) "63687228363729" 116string(14) "63687228363829" 117string(14) "63687228363929" 118string(14) "63687228373029" 119string(14) "63687228373129" 120string(14) "63687228373229" 121string(14) "63687228373329" 122string(14) "63687228373429" 123string(14) "63687228373529" 124string(14) "63687228373629" 125string(14) "63687228373729" 126string(14) "63687228373829" 127string(14) "63687228373929" 128string(14) "63687228383029" 129string(14) "63687228383129" 130string(14) "63687228383229" 131string(14) "63687228383329" 132string(14) "63687228383429" 133string(14) "63687228383529" 134string(14) "63687228383629" 135string(14) "63687228383729" 136string(14) "63687228383829" 137string(14) "63687228383929" 138string(14) "63687228393029" 139string(14) "63687228393129" 140string(14) "63687228393229" 141string(14) "63687228393329" 142string(14) "63687228393429" 143string(14) "63687228393529" 144string(14) "63687228393629" 145string(14) "63687228393729" 146string(14) "63687228393829" 147string(14) "63687228393929" 148string(16) "6368722831303029" 149string(16) "6368722831303129" 150string(16) "6368722831303229" 151string(16) "6368722831303329" 152string(16) "6368722831303429" 153string(16) "6368722831303529" 154string(16) "6368722831303629" 155string(16) "6368722831303729" 156string(16) "6368722831303829" 157string(16) "6368722831303929" 158string(16) "6368722831313029" 159string(16) "6368722831313129" 160string(16) "6368722831313229" 161string(16) "6368722831313329" 162string(16) "6368722831313429" 163string(16) "6368722831313529" 164string(16) "6368722831313629" 165string(16) "6368722831313729" 166string(16) "6368722831313829" 167string(16) "6368722831313929" 168string(16) "6368722831323029" 169string(16) "6368722831323129" 170string(16) "6368722831323229" 171string(16) "6368722831323329" 172string(16) "6368722831323429" 173string(16) "6368722831323529" 174string(16) "6368722831323629" 175string(16) "6368722831323729" 176string(16) "6368722831323829" 177string(16) "6368722831323929" 178string(16) "6368722831333029" 179string(16) "6368722831333129" 180string(16) "6368722831333229" 181string(16) "6368722831333329" 182string(16) "6368722831333429" 183string(16) "6368722831333529" 184string(16) "6368722831333629" 185string(16) "6368722831333729" 186string(16) "6368722831333829" 187string(16) "6368722831333929" 188string(16) "6368722831343029" 189string(16) "6368722831343129" 190string(16) "6368722831343229" 191string(16) "6368722831343329" 192string(16) "6368722831343429" 193string(16) "6368722831343529" 194string(16) "6368722831343629" 195string(16) "6368722831343729" 196string(16) "6368722831343829" 197string(16) "6368722831343929" 198string(16) "6368722831353029" 199string(16) "6368722831353129" 200string(16) "6368722831353229" 201string(16) "6368722831353329" 202string(16) "6368722831353429" 203string(16) "6368722831353529" 204string(16) "6368722831353629" 205string(16) "6368722831353729" 206string(16) "6368722831353829" 207string(16) "6368722831353929" 208string(16) "6368722831363029" 209string(16) "6368722831363129" 210string(16) "6368722831363229" 211string(16) "6368722831363329" 212string(16) "6368722831363429" 213string(16) "6368722831363529" 214string(16) "6368722831363629" 215string(16) "6368722831363729" 216string(16) "6368722831363829" 217string(16) "6368722831363929" 218string(16) "6368722831373029" 219string(16) "6368722831373129" 220string(16) "6368722831373229" 221string(16) "6368722831373329" 222string(16) "6368722831373429" 223string(16) "6368722831373529" 224string(16) "6368722831373629" 225string(16) "6368722831373729" 226string(16) "6368722831373829" 227string(16) "6368722831373929" 228string(16) "6368722831383029" 229string(16) "6368722831383129" 230string(16) "6368722831383229" 231string(16) "6368722831383329" 232string(16) "6368722831383429" 233string(16) "6368722831383529" 234string(16) "6368722831383629" 235string(16) "6368722831383729" 236string(16) "6368722831383829" 237string(16) "6368722831383929" 238string(16) "6368722831393029" 239string(16) "6368722831393129" 240string(16) "6368722831393229" 241string(16) "6368722831393329" 242string(16) "6368722831393429" 243string(16) "6368722831393529" 244string(16) "6368722831393629" 245string(16) "6368722831393729" 246string(16) "6368722831393829" 247string(16) "6368722831393929" 248string(16) "6368722832303029" 249string(16) "6368722832303129" 250string(16) "6368722832303229" 251string(16) "6368722832303329" 252string(16) "6368722832303429" 253string(16) "6368722832303529" 254string(16) "6368722832303629" 255string(16) "6368722832303729" 256string(16) "6368722832303829" 257string(16) "6368722832303929" 258string(16) "6368722832313029" 259string(16) "6368722832313129" 260string(16) "6368722832313229" 261string(16) "6368722832313329" 262string(16) "6368722832313429" 263string(16) "6368722832313529" 264string(16) "6368722832313629" 265string(16) "6368722832313729" 266string(16) "6368722832313829" 267string(16) "6368722832313929" 268string(16) "6368722832323029" 269string(16) "6368722832323129" 270string(16) "6368722832323229" 271string(16) "6368722832323329" 272string(16) "6368722832323429" 273string(16) "6368722832323529" 274string(16) "6368722832323629" 275string(16) "6368722832323729" 276string(16) "6368722832323829" 277string(16) "6368722832323929" 278string(16) "6368722832333029" 279string(16) "6368722832333129" 280string(16) "6368722832333229" 281string(16) "6368722832333329" 282string(16) "6368722832333429" 283string(16) "6368722832333529" 284string(16) "6368722832333629" 285string(16) "6368722832333729" 286string(16) "6368722832333829" 287string(16) "6368722832333929" 288string(16) "6368722832343029" 289string(16) "6368722832343129" 290string(16) "6368722832343229" 291string(16) "6368722832343329" 292string(16) "6368722832343429" 293string(16) "6368722832343529" 294string(16) "6368722832343629" 295string(16) "6368722832343729" 296string(16) "6368722832343829" 297string(16) "6368722832343929" 298string(16) "6368722832353029" 299string(16) "6368722832353129" 300string(16) "6368722832353229" 301string(16) "6368722832353329" 302string(16) "6368722832353429" 303string(16) "6368722832353529" 304 305*** Testing htmlentities() with NULL as first,second and third argument *** 306string(42) "‚†™Ÿ€‚�" 307string(0) "" 308string(0) "" 309string(0) "" 310string(0) "" 311 312*** Checking for proper memory allocation with long string *** 313string(198) "‚†™Ÿ€‚†„€‰…ƒ†„€‘ƒ‘†‡…†ˆ‚‰’‘ƒ" 314 315*** Testing a normal string with htmlentities() *** 316string(42) "<html> This is a test! </html>" 317 318*** Testing htmlentites() on a quote *** 319string(36) "A 'quote' is <b>bold</b>" 320string(46) "A 'quote' is <b>bold</b>" 321string(36) "A 'quote' is <b>bold</b>" 322string(36) "A 'quote' is <b>bold</b>" 323 324*** Testing error conditions *** 325 326Warning: htmlentities() expects at least 1 parameter, 0 given in %s on line %d 327NULL 328string(14) "„‘" 329Done 330