Re: HTML parse trees...

From: Date: Thu, 15 Jun 2000 01:58:15 +0000
Subject: Re: HTML parse trees...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-1902@lists.php.net to get a copy of this message
> I'm in the process of writing the same old same old stupid code, something > like this: > > 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. -Rasmus

« previous php.general (#1902) next »