You are here: Re: Multi - level parsing « PHP Language « IT news, forums, messages
Re: Multi - level parsing

Posted by Michael on 02/03/07 17:21

Hey Rik,

Wow that sounds complicated :)
I just thought up a method of inside-out parsing (don't know if it's gonna
work though, haven't had time to type it out)

function ParseTag($contents) {
Find a complete tag at position n...n+p (simple regex will do)
Check if it's contents contain another tag.
If not, process the tag we found
If it does, ParseTag(substr($contents, n+p+1)) and start over
}

Long example: in
[first][first]Hello [second]beautiful
[first]world![/first][/second][/first][/first]
this would first match a "first" tag, with contents
[first]Hello [second]beautiful [first]world!
this contains an opening tag, so find look at
[first]Hello [second]beautiful
[first]world![/first][/second][/first][/first]
we find a "first" tag with contents
Hello [second]beautiful [first]world!
containing another tag, so we parse
Hello [second]beautiful [first]world![/first][/second][/first][/first]
matching a second tag with
beautiful [first]world![/first]
so we parse
beautiful [first]world![/first]
and find a self-contained first-tag. We can process it, replacing the
original string
[first][first]Hello [second]beautiful
[first]world![/first][/second][/first][/first]
by (assume "[first]text[/first]" processes as ""text"")
[first][first]Hello [second]beautiful
"world"[/second][/first][/first]
and now we start the process all over -- replacing the second tag -- and
over until all tags have been resolved.

Any traling opening or closing tags will not form a problem as the regex
will only match opening tags with a closing tag.
Only problem is, for large documents this may become slow.

Vriendelijke groet

Michael

PS I should find out if Wikipedia allows nested tags. If so I can perhaps
try to find my way through their sourcecode... not looking forward to that
though.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация