PageRenderTime 35ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/good/ext/standard/tests/strings/htmlspecialchars.php

http://github.com/facebook/hiphop-php
PHP | 43 lines | 25 code | 8 blank | 10 comment | 3 complexity | 799eb8f3b9bb37f69ab8b6cd33c0ad3d MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?hh
  2. /* Prototype: string htmlspecialchars ( string $string [, int $quote_style [, string $charset]] );
  3. Description: Convert special characters to HTML entities
  4. */
  5. /* retrieving htmlspecialchars from the ANSI character table */
  6. <<__EntryPoint>> function main(): void { echo "*** Retrieving htmlspecialchars for 256 characters ***\n";
  7. for($i=0; $i<256; $i++)
  8. var_dump( bin2hex( htmlspecialchars(b"chr($i)") ) );
  9. /* giving strange arguments */
  10. echo "\n*** Testing htmlspecialchars() with NULL as first, second and third argument ***\n";
  11. var_dump( htmlspecialchars("<br>", 0, 'iso-8859-1') );
  12. var_dump( htmlspecialchars("<br>", ENT_NOQUOTES, '') );
  13. var_dump( htmlspecialchars("<br>", ENT_QUOTES, '') );
  14. var_dump( htmlspecialchars("<br>", ENT_COMPAT, '') );
  15. var_dump( htmlspecialchars('', 0, '') );
  16. /* giving long string to check for proper memory re-allocation */
  17. echo "\n*** Checking a long string for proper memory allocation ***\n";
  18. 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' ) );
  19. /* Giving a normal string */
  20. echo "\n*** Testing a normal string with htmlspecialchars() ***\n";
  21. var_dump( htmlspecialchars("<br>Testing<p>New file.</p> ", ENT_QUOTES, 'iso-8859-1' ) );
  22. /* checking behavior of quote */
  23. echo "\n*** Testing htmlspecialchars() on a quote...\n";
  24. $str = "A 'quote' is <b>bold</b>";
  25. var_dump( htmlspecialchars($str) );
  26. var_dump( htmlspecialchars($str, ENT_QUOTES) );
  27. var_dump( htmlspecialchars($str, ENT_NOQUOTES) );
  28. var_dump( htmlspecialchars($str, ENT_COMPAT) );
  29. echo "\n*** Testing error conditions ***\n";
  30. /* zero argument */
  31. try { var_dump( htmlspecialchars() ); } catch (Exception $e) { echo "\n".'Warning: '.$e->getMessage().' in '.__FILE__.' on line '.__LINE__."\n"; }
  32. /* giving arguments more than expected */
  33. var_dump( htmlspecialchars("<br>",ENT_QUOTES,'iso-8859-1', true) );
  34. echo "Done\n";
  35. }