Hello, I'm writing a routine that recursively reads an HTML document, looking for "special tags". It's a template system, but contrary to what I've seen out there so far, no template engines allow for any kind of customization from within the document; they only seem to be variable replacement systems.
What I have in mind is something along the lines of: <HTML> blah blah {MAGICTAG param1=a param2=b}some more {ANOTHERTAG}text{/ANOTHERTAG} here {/MAGICTAG} blah </HTML> The text between ANOTHERTAG would first be changed and then passed along with the other text to MAGICTAG. ie, the data is treated from the inside out, and nesting is obviously supported. I've got everything working, but the problem is I'm using quite a few "ereg" statements recursively, so performance is not so good. Here's a simplified version of the core (it's part of a class, and I modified the code for a "standalone" version here). Thanks in advance for any ideas. Feel free to recycle this code. function parse( $template ) { //Look for (before*) {a tag} (after*) anything and store matches in $regs if( ereg( "(.*)[{]([a-zA-Z0-9]+)[}](.*)", $template, $regs ) ) { $before = $regs[1]; $tag = $regs[2]; //Now look for (data*) {/closing tag} (after*) in the "after" portion of first match if( ereg( "(.*)[{][/]" . $tag. "[}](.*)", $regs[3], $regs ) ) { $after = $regs[2]; $data = $regs[1]; $resolvedTag = initHandler( $tag, $data ); //handle this tag and data } //support for "standalone" tags (no {/closing tag} ) else { ereg( "(.*)", $regs[3], $regs ); $resolvedTag = getTagValue( $tag ); $after = $regs[1]; } } if( $resolvedTag ) { $template = $before . $resolvedTag . $after; parse( $template ); } else { return $template; } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php