Advertisement
zero50x

Закрытие незакрытых тегов на tidy

Aug 22nd, 2016
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.00 KB | None | 0 0
  1. <?
  2. // Документация к tidy http://php.net/manual/ru/book.tidy.php
  3.  
  4.     error_reporting(0);
  5. $html = $_POST['html'];
  6. $config = array( 'indent'         => false,
  7.             'output-xhtml'   => false,
  8.             'show-body-only'   => 1,
  9.             'wrap'           => 200);
  10. $Tidy = new tidy();
  11. $Tidy->parseString($html, $config, 'utf8');
  12. $Tidy->cleanRepair();
  13.  
  14.  
  15.  
  16. $html = $Tidy;
  17.  preg_match_all("#\<(.*?)\>#s", $html, $otv,PREG_OFFSET_CAPTURE);
  18.   //print_r($otv);
  19.  
  20.  
  21.   for($i=0;$i<count($otv[0]);$i++){
  22.    if($otv[1][$i][0] == $otv[1][$i+1][0]) {
  23.  
  24.      $html = str_replace("<".$otv[1][$i][0]."><".$otv[1][$i][0].">", "<".$otv[1][$i][0].">", $html);
  25.  
  26.    }
  27.   }
  28.  
  29. $Tidy->parseString($html, $config, 'utf8');
  30. $Tidy->cleanRepair();
  31.  
  32. echo "<pre>" . htmlspecialchars($Tidy) . "</pre>";
  33.  
  34.   ?>
  35.  
  36. <!DOCTYPE html>
  37. <html lang="en">
  38.  
  39. <head>
  40.    
  41.  
  42.   </head>
  43.  
  44. <body>
  45.  
  46.  
  47.  
  48. <div class="main">
  49.  
  50.     <div class="main-inner">
  51.  
  52.         <div class="container">
  53.  
  54.           <div class="row">
  55.  
  56.             <div class="span12">
  57.  
  58.                 <div class="widget ">
  59.  
  60.                     <div class="widget-header">
  61.                         <h3></h3>
  62.                     </div> <!-- /widget-header -->
  63.  
  64.                     <div class="widget-content">
  65.  
  66.                    <p class="help-block">HTML текст</p>
  67.                         <form id="edit-profile"  action="1.php" method="post">
  68.                                               <textarea name="html"> </textarea>     <br>
  69.                                                        <br>
  70.                                                 <input type="submit">
  71.  
  72.                                                 </form>
  73.                         </div>
  74.  
  75.  
  76.  
  77.  
  78.  
  79.                     </div> <!-- /widget-content -->
  80.  
  81.                 </div> <!-- /widget -->
  82.  
  83.             </div> <!-- /span8 -->
  84.  
  85.  
  86.  
  87.  
  88.           </div> <!-- /row -->
  89.  
  90.         </div> <!-- /container -->
  91.  
  92.     </div> <!-- /main-inner -->
  93.  
  94. </div> <!-- /main -->
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106. <script src="js/jquery-1.7.2.min.js"></script>
  107.  
  108. <script src="js/bootstrap.js"></script>
  109. <script src="js/base.js"></script>
  110.  
  111.  
  112.   </body>
  113.  
  114. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement