toddlikesdesign
toddlikesdesign

Reputation: 53

Prevent HTML Tidy from stripping PHP

I have gone through the docs but am not seeing how I can prevent tidy from stripping my PHP. My config is as follows:

anchor-as-name: no
doctype: omit
drop-empty-paras: no
fix-uri: no
literal-attributes: yes
merge-divs: no
merge-spans: no
numeric-entities: no
preserve-entities: yes
quote-ampersand: no
quote-marks: no
show-body-only: yes
indent: auto
indent-spaces: 4
tab-size: 4
wrap: 0
wrap-asp: no
wrap-jste: no
wrap-php: no
wrap-sections: no
tidy-mark: no
new-blocklevel-tags: article,aside,command,canvas,dialog,details,figcaption,figure,footer,header,hgroup,menu,nav,section,summary,meter 
new-inline-tags: video,audio,canvas,ruby,rt,rp,time,meter,progress,datalist,keygen,mark,output,source,wbr
force-output: yes
quiet: yes
show-warnings: yes

Upvotes: 2

Views: 656

Answers (1)

txyoji
txyoji

Reputation: 6868

It doesn't appear there is a way to use tidy in php like this. (Even as of php 5.5) After trying lots of variations including stuff which should be valid SGML like <script language="php"> and <!-- <?php echo 1; ?> !--> It appears its actively stripping out php tags.

The tidy library in php is most often used as an output filter; something that takes all the output of your page before its sent to the browser and fixes it. The most basic example of this is right out of the php manual.

<?php
//start the output buffer to capture all page output.
ob_start();
?>
<html>a html document
     <div><?php echo 'do your thing here' ?></div>
</html>
<?php
//get the contents of the output buffer.
$html = ob_get_clean();

// configure tidy
$config = array(
           'indent'         => true,
           'output-xhtml'   => true,
           'wrap'           => 200);
//tidy the html
$tidy = new tidy;
$tidy->parseString($html, $config, 'utf8');
$tidy->cleanRepair();
// Output the clean html.
echo $tidy;

Upvotes: 1

Related Questions