cleanhtml5.php 846 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /*
  3. * cleanhtml5.php
  4. *
  5. * A simple script to clean and repair HTML,XHTML,PHP,ASP,etc. documents
  6. * if no file is provided, it reads from standard input.
  7. *
  8. * NOTE: Works only with tidy for PHP 5, for tidy in PHP 4.3.x see cleanhtml.php
  9. *
  10. * By: John Coggeshall <john@php.net>
  11. *
  12. * Usage: php cleanhtml5.php [filename]
  13. *
  14. */
  15. if(!isset($_SERVER['argv'][1])) {
  16. $data = file_get_contents("php://stdin");
  17. $tidy = tidy_parse_string($data);
  18. } else {
  19. $tidy = tidy_parse_file($_SERVER['argv'][1]);
  20. }
  21. $tidy->cleanRepair();
  22. if(!empty($tidy->errorBuffer)) {
  23. echo "\n\nThe following errors or warnings occurred:\n";
  24. echo "{$tidy->errorBuffer}\n";
  25. }
  26. echo $tidy;
  27. ?>