tags:

views:

1178

answers:

5

Does anybody know of a good tool that cleans up files with php and html in it? I've used Tidy before but it doesn't do a good job at leaving the php code alone. I know there are various implementations of tidy but does any tool reign champion specifically for pages with html and php?

Thanks

A: 

As far as I know, Tidy is the "reigning champion" when is comes to cleaning html code. The only other tool I've personally used in cleaning code is within Adobe Dreamweaver.

Abinadi
+1  A: 

Cleaning your code starts with separating PHP from HTML !

Boris Guéry
Sounds good, but not everything can be seperated. For me it works though, to put most logic in a great php-block on top, then a clean html-doc beneath in the file with simple short <?=myphpfunction()?>. Sometimes I do need <?while () {?> and closing inside the html code too. So how do you manage to clean out php from html?
BeowulfOF
I believe there is nothing wrong with loops in a template file; most of the templating engines I can name support this structure. It's about separating business logic from presentation logic. Put your "real" code in file.php, and include("templates/file.tpl.php") which mostly looks like an HTML file but has some PHP tags for looping and echoing vars. (That is, if you don't want to use Smarty or Dwoo or another templating engine.)The alternate syntax can help here: http://us3.php.net/manual/en/control-structures.alternative-syntax.php
Adam Backstrom
You should place the HTML block to a separate file that you treat as a template. To that you will then only forward variables it needs and use minimal PHP inside it. Or use a separate templating system at all (like Smarty). Then you should be able to run Tidy on that file and get reasonable results. Although it will probably still need some human touch as you can't really expect Tidy to understand the meaning of the PHP between HTML segments.
Rene Saarsoo
Totally agree with you Rene Saarsoo.. It was what i wanted to focus !
Boris Guéry
A: 

I would agree with seperating your HTML and your PHP code. However, I think you have to think of it kind of backwards. I would seperate your HTML code from your PHP code. Take your HTML and block it up and use include 'html_code_1.php';. Thus you can run Tidy on your HTML and not worry about it affecting your PHP code.

JoshFinnie
A: 

I previously had this problem, however had issues with other programs reorganizing what I coded, and trying to clean it up usually ended up doing more harm than good. To solve this, I am starting to learn the ins and outs of Code Igniter, a basic PHP framework that uses the MVC approach to splitting HTML and PHP. I haven't tested much, but it looks like much less hassle than writing HTML and PHP straight into the single file.

Lobe
A: 

You can use this PHP class, if you can't install the "Tidy" module (sometimes when you buy hosts you can't).

http://www.barattalo.it/html-fixer/

Pons