Php tidy and text areas Php tidy and text areas php php

Php tidy and text areas


If sdfds is outputed with php you will need to add another config option.

 $config = array('indent' => TRUE, 'output-html' => TRUE, 'wrap' => 0, 'wrap-php' => 0);

Wrap only worries about html and any php statements are treated as a new line. For more information on config options you can visit: http://tidy.sourceforge.net/docs/quickref.html


When you use indent => true you will get messed up texareas with tidy. It gets to tidy because even the textareas value is indented. If you want your textareas to appear correct you could just set indent => false. This will tidy up your HTML, but will also leave your textarea with the same value after applying tidy. I have seen there are some patches which solves the problem, but then you should compile tidy yourself. You could also do this with PHP but then you are tidying up tidy.


Tidy can be rally a "messy" sometimes and needs further refinement with rexep, here is a workaround that will put the cursor on the same line in the final output, so the usability doesn't suffer. Just run your tidied html trough:

$subject = preg_replace('%(\r\n|\n)(?=</textarea>)%sim', '', $subject);