title: PHP Tidy: Breaks textareas
body: <p>I have a html form page (test.php) with 2 textareas and a submit button. Instead of copying the source code that I want to format and hardcode it everytime, I have created the first textarea so that I can copy the to-be-cleaned code into it. Then upon pressing the submit button, the form posts to the same page and shows the tidified source code in the 2nd text area. <strong>Displaying this tidified source code is the problem.</strong>  Passing the following code through HTML tidy and trying to display the output in a textarea, breaks the output display. What I mean by that is, if you notice, I have <code>&lt;/textarea&gt;</code> inside of the following html code. As soon as Tidy encounters it, it's closing textarea and parsing the rest of the info of the source code as if it were a part of the HTML document, thereby breaking my entire html form page (test.php).</p>
  
  <p><strong>SAMPLE SOURCE CODE THAT I AM PASSING TO HTML TIDY:</strong></p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;Hi&lt;/title&gt;
  &lt;link href="css/styles.css" rel="stylesheet" type="text/css" /&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;div id="wrapper"&gt;
  
  &lt;h1 data-title="Hi"&gt; &lt;a href="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;"&gt; Hi &lt;/a&gt; &lt;/h1&gt;  
  
  &lt;form name="form1" method="post" action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;"&gt;
  
    &lt;textarea name="comments" id="comments" cols="150" rows="15"&gt;&lt;?php echo (isset($_POST['comments']) ? $_POST['comments'] : '' ); ?&gt;&lt;/textarea&gt;
    &lt;br&gt;
    &lt;input type="submit" name="sbt_process" id="sbt_process" value="Submit"&gt;
  &lt;/form&gt;
  
  &lt;textarea name="css" id="css" cols="150" rows="18"&gt;&lt;?php echo (isset($text) ? $text : ''); ?&gt;&lt;/textarea&gt;
  
  &lt;/div&gt;&lt;!-- #wrapper --&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>HTML TIDY PARAMTERS:</strong></p>
  
  <pre><code>$params_body = array(
      'break-before-br'       =&gt; 'no',
      'clean'                 =&gt; 'clean',
      'doctype'               =&gt; 'strict',
      'drop-empty-paras'      =&gt; 'yes',
      'drop-font-tags'        =&gt; 'yes',
      'force-output'          =&gt; 'yes',
      'indent'                =&gt; TRUE, //'yes',
      'indent-attributes'     =&gt; FALSE,
      'indent-spaces'         =&gt; 4,
      'input-encoding'        =&gt; 'utf8',
      'join-styles'           =&gt; 'yes',
      'literal-attributes'    =&gt; 'yes', //This option specifies if Tidy should ensure that whitespace characters within attribute values are passed through unchanged.
      'logical-emphasis'      =&gt; 'yes',
      'lower-literals'        =&gt; 'yes',
      'merge-divs'            =&gt; 'no',
      'merge-spans'           =&gt; 'yes',
      'output-encoding'       =&gt; 'ascii',
      'output-xhtml'          =&gt; 'yes',
      //'output-xml'          =&gt; true,
      'output-bom'            =&gt; 'no',
      'preserve-entities'     =&gt; 'yes',
      'quiet'                 =&gt; 'yes',
      'quote-ampersand'       =&gt; 'yes',
      'quote-marks'           =&gt; 'no',
      'quote-nbsp'            =&gt; TRUE, 
      'show-body-only'        =&gt; FALSE,
      'show-errors'           =&gt; 0,
      'show-warnings'         =&gt; 0,
      'sort-attributes'       =&gt; 'alpha',
      'vertical-space'        =&gt; TRUE, //'yes',
      'wrap'                  =&gt; 0, //This option specifies the right margin Tidy uses for line wrapping. Tidy tries to wrap lines so that they do not exceed this length. Set wrap to zero if you want to disable line wrapping.
      'wrap-attributes'       =&gt; FALSE,
      'tab-size'              =&gt; 20, //This option specifies the number of columns that Tidy uses between successive tab stops. It is used to map tabs to spaces when reading the input. Tidy never outputs tabs.
      'wrap-php'              =&gt; 0,
      'wrap-script-literals'  =&gt; TRUE,
      'escape-cdata'          =&gt; TRUE,
      'indent-cdata'          =&gt; TRUE,
      'numeric-entities'      =&gt; FALSE,
      'fix-uri'               =&gt; FALSE,
      'markup'                =&gt; TRUE
  );
  </code></pre>
  
  <p>I have been messing around with the different params of php tidy, but its of no use. I even tried to output it as XML, but that did not help. How can I make Tidy show the cleaned source code in the 2nd textarea correctly without breaking/parsing the <code>&lt;/textarea&gt;</code> tag of the source code that I am trying to clean?</p>