HTML_Safe
[ class tree: HTML_Safe ] [ index: HTML_Safe ] [ all elements ]

Source for file HTML_Safe_example.php

Documentation is available at HTML_Safe_example.php

  1. <?php
  2. /*
  3.  
  4.     Example for Safehtml
  5.  
  6. */
  7.  
  8. define('XML_HTMLSAX3'dirname(__FILE__)."/classes/");
  9. ?>
  10. <html>
  11. <head>
  12.   <style>
  13.   STRIKE, S { color:#999999 }
  14.   </style>
  15. </head>
  16. <body>
  17. <h2>SAFEHTML Testing interface</h2>
  18. This parser strip down all potentially dangerous content within HTML:
  19. <ul>
  20. <li> opening tag without its closing tag
  21. <li> closing tag without its opening tag
  22. <li> any of these tags: "base", "basefont", "head", "html", "body", "applet", "object", "iframe", "frame", "frameset", "script", "layer", "ilayer", "embed", "bgsound", "link", "meta", "style", "title", "blink", "xml" etc.
  23. <li> any of these attributes: on*, data*, dynsrc
  24. <li> javascript:/vbscript:/about: etc. protocols
  25. <li> expression/behavior etc. in styles
  26. <li> any other active content
  27. </ul>
  28. <p>If you found any bugs in this parser, please inform me &mdash; ICQ:551593 or <a href=mailto:thingol@mail.ru>thingol@mail.ru</a> - Roman Ivanov.
  29.  
  30. <form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">
  31. <textarea name="html" rows="10" cols="100">
  32. <?
  33. if (isset($_POST["html"])) 
  34. {
  35.  $_POST["html"] = stripslashes($_POST["html"]);
  36.  echo htmlspecialchars($_POST["html"]);
  37. }
  38. ?>
  39. </textarea>
  40. <input type="submit">
  41. </form>
  42. <?php
  43. require_once('classes/safehtml.php');
  44.  
  45. function getmicrotime()
  46.   list($usec$secexplode(" ",microtime())
  47.   return ((float)$usec + (float)$sec)
  48. }
  49.  
  50.  
  51. if (isset($_POST["html"])) 
  52. {
  53.  $doc=$_POST["html"];
  54.  
  55.  // Instantiate the handler
  56.  $safehtml =new safehtml();
  57.  
  58.  echo ('<pre>');
  59.  // Time HTMLSax
  60.  $start getmicrotime();
  61.  $result $safehtml->parse($doc);
  62.  echo "Parsing took seconds:\t\t".(getmicrotime()-$start) );
  63.  echo ('</pre>');
  64.  
  65.  echo ('<b>Source code after filtration:</b><br/>');
  66.  echo htmlspecialchars($result) );
  67.  
  68.  echo ('<p><b>Code after filtration as is (HTML):</b><br/>');
  69.  echo $result );
  70. }
  71. ?>
  72. <hr>
  73. <h3>Many thanks:</h3>
  74. <ul>
  75. <li> HTMLSax authors
  76. <li> lj user=BOLK
  77. <li> lj user=ati & lj user=curiousweasel
  78. <li> lj user=teplorod
  79. <li> Boris Bogdanov
  80. <li> Mash
  81. <li> lj user=electrocat
  82. <li> shmel
  83. <li> John "Gozzy" Godsland
  84. <li> Christian Stocker
  85. <li> Nick Cleaton
  86. </ul>
  87. <hr /> <a href="http://pixel-apes.com/safehtml">Download Safehtml</a>.
  88. <br /> Copyright &copy; 2004-2005, Roman Ivanov.
  89. <br /> All rights reserved.
  90.  
  91. </body>
  92. </html>

Documentation generated on Mon, 11 Mar 2019 14:15:02 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.