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