HTML Formatter

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mantrax
Forum Newbie
Posts: 5
Joined: Sun Sep 19, 2004 5:58 am
Location: Italy - Asolo (Treviso)

HTML Formatter

Post 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?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Cool, hadn't realised they'd ported HTML tidy to PHP.

Mac
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

yeah i learnt it 2 days ago while searching in zend.com :)
User avatar
mantrax
Forum Newbie
Posts: 5
Joined: Sun Sep 19, 2004 5:58 am
Location: Italy - Asolo (Treviso)

Post by mantrax »

How is used the tidy functions?
can you quickly explain it to me?
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

Click on the link above and there's an example for it.I didn't use it before either.. :(
User avatar
mantrax
Forum Newbie
Posts: 5
Joined: Sun Sep 19, 2004 5:58 am
Location: Italy - Asolo (Treviso)

Post by mantrax »

thanks much, tidy functions are very useful
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

no tidy for php 4 that I can find :cry:
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

you can always use outputbuffering, let tidy clean (binary) clean the output, and then spit out that cleaned up html ;)
Post Reply