Re: HTML parse trees...
| From: | Christian Goetze | Date: | Thu, 15 Jun 2000 02:01:19 +0000 |
| Subject: | Re: HTML parse trees... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-1903@lists.php.net to get a copy of this message | ||
On Wed, 14 Jun 2000, Rasmus Lerdorf wrote:
> > function _($tag, $attributes='', $content='') {
> > $html = '<'.$tag;
> > if (is_array($attributes)) {
> > while ($attribute = each($attributes)) {
> > if (is_int($attribute[1])) {
> > $html .= ' '.$attribute[0].'='.$attribute[1];
> > } elseif (is_string($attribute[1])) {
> > $html .= '
> > '.$attribute[0].'="'.$attribute[1].'"';
> > } elseif ($attribute[1]) {
> > $html .= ' '.$attribute[0];
> > }
> > }
> > } else {
> > $content = $attributes.$content;
> > }
> > if ($content) {
> > return $html.'>'.$content.'</'.$tag.'>';
> > } else {
> > return $html.'>';
> > }
> > }
> > Now I can't imagine that I'd be the first to do this, and I'm also seeing
> > that this whole thing is going to end up being quite inefficient. All
> > these string concatenations...
> >
> > Anyway, how come PHP doesn't have built in support for HTML (or XML) parse
> > trees and functions to build them, store them and dump them efficiently?
> PHP has 2 XML parsers. HTML is difficult to parse because it tends to not
> conform to a clean dtd.
I'm actually more interested in the UNparsing :) of HTML. I'd like to have
primitives as above that will build the parse tree and then dump it as
HTML.
--
cg