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