Page 1 of 1

HTML Formatter

Posted: Sat Oct 09, 2004 1:59 pm
by mantrax
I have need of a script formatting a string containing HTML code
example:
string:
"<html><head><title>example</title></head><body>body</body></html>"
output:

Code: Select all

<html>
    <head>
         <title>example</title>
    </head>
    <body>
         body
    </body>
</html>
How i can do?

Posted: Sat Oct 09, 2004 2:15 pm
by twigletmac
Are you going to be doing this regularily to code entered into a CMS (or something like that) or are you just trying to tidy your own code?

Mac

Posted: Sat Oct 09, 2004 6:04 pm
by mudkicker
you can use php's tidy module.
just uncomment php_tidy.dll in php.ini (in php5 it is bundled but in php4 i don't know)
(if you have an access) ;)

look @ ->
http://www.zend.com/php5/articles/php5-tidy.php

Posted: Sun Oct 10, 2004 6:13 am
by twigletmac
Cool, hadn't realised they'd ported HTML tidy to PHP.

Mac

Posted: Sun Oct 10, 2004 6:15 am
by mudkicker
yeah i learnt it 2 days ago while searching in zend.com :)

Posted: Mon Oct 11, 2004 1:09 pm
by mantrax
How is used the tidy functions?
can you quickly explain it to me?

Posted: Mon Oct 11, 2004 1:13 pm
by mudkicker
Click on the link above and there's an example for it.I didn't use it before either.. :(

Posted: Tue Oct 12, 2004 10:13 am
by mantrax
thanks much, tidy functions are very useful

Posted: Tue Oct 12, 2004 10:17 am
by phpScott
no tidy for php 4 that I can find :cry:

Posted: Tue Oct 12, 2004 10:45 am
by timvw
you can always use outputbuffering, let tidy clean (binary) clean the output, and then spit out that cleaned up html ;)