Suggestions for an indenter for an HTML writer

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
jolinar
Forum Commoner
Posts: 61
Joined: Tue May 24, 2005 4:24 pm
Location: in front of computer

Suggestions for an indenter for an HTML writer

Post by jolinar »

I have a problem with some code I'm working on. When the XHTML in a gallery project I have been working on became too complex, I decided that I should start again, but this time with an HTML writer class. What I want to achieve is automatic indentation and a memory of it every time a new tag is opened. I think I can do this by incrementing every time an open function is called and decrementing every time a close function is called.

Here is the problem, I don't know how to create blank spaces which are dependent on an integer. (int = 1, 1 space etc). Does anyone know how I might go about this? (or any better ideas to what I'm trying to do)
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

str_repeat() is a great function for doing exactly that.
User avatar
jolinar
Forum Commoner
Posts: 61
Joined: Tue May 24, 2005 4:24 pm
Location: in front of computer

Post by jolinar »

I've managed to solve the problem by having a class variable initiated when the class is created. This is set to 0. Then a new tag is opened it is incremented, all tags will insert spaces and have the tag content appended to this string, when tags are closed, it is decremented
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Why reinvent the wheel? Use tidy
Post Reply