Page 1 of 1

Suggestions for an indenter for an HTML writer

Posted: Fri Jul 15, 2005 11:31 am
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)

Posted: Fri Jul 15, 2005 12:25 pm
by onion2k
str_repeat() is a great function for doing exactly that.

Posted: Sat Jul 16, 2005 11:01 am
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

Posted: Sat Jul 16, 2005 3:19 pm
by timvw
Why reinvent the wheel? Use tidy