HTML Parsing Indenter

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

HTML Parsing Indenter

Post by jolinar »

At the moment I'm working on an HTML generator writer. The idea is that there is a generator class, which will generate HTML tags. These tags (and the text) are stored in a list until the document is finished, and is then passed on to a writer class.

Here is the difficult bit, I want to be able to go through the tags and parse them for opening and closing. So if it detects < with no ! then it increments the indent, and if it finds a </ tag then it will decrement the indent (and tags finishing in /> have no effect)

Does anyone have any ideas for how I can process the strings, I have a fair idea on the comparison operation, it is just isolating parts of the string
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

1. Most common method : Regular Expressions
2. Dont know how, but I think xml_parse can also do.
Post Reply