Unparsing HTML

From: Date: Sun, 18 Jun 2000 04:21:01 +0000
Subject: Unparsing HTML
Groups: php.dev 
Request: Send a blank email to php-dev+get-21664@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? Before I go out of my way to figure out how to implement these myself, I thought I'd ask... -- cg

« previous php.dev (#21664) next »