[code=php]
<? 
// begin class

class htmlTag{
	/*
	@var	bool
	*/
	private $shortTag;
	/*
	@var	string
	*/
	private $text;
	/*
	@var	string
	*/
	protected $tagName;
	/*
	@var	array
	*/
	protected $attributes;
	/*
	@var	array
	*/
	protected $childs;
	
		
	/*
		instantie aanmaken 
		@param		string 		naam van het object bv: strong, a, li, input, enz...

	*/
	public function __construct($iTagName = NULL){
	
		if(isset($iTagName)){
			$this -> tagName = (string) $iTagName;
		}
		$this -> attributes = array();
		$this -> childs = array();
	}	
	
	/*
	@method		tellen van het aantal childs
	*/
	public function countChilds(){
	
		return count($this -> childs);
	
	}
	
	public function getChilds(){
	
		return $this -> childs;
	
	}
	
	/*
	@method		atribuut toevoegen of aanpassen
	@param		string		naam van het atribuut bv: href, value, class
	@param		string		value
	*/
	public function setAttribute($iName, $iValue){
		
		$this -> attributes[$iName] = (string) $iValue;
	
	}
	
	public function getAttribute($iName){
	
		if(array_key_exists($iName, $this -> attributes)){
		
			return $this -> attributes[$iName];
		
		}
	
	}
	
	/*
	@method		tagnaam aanpassen
	*/
	
	public function setTagName($iTagName){
	
		$this -> tagName = (string) $iTagName;
	
	}
	
	
	/*
	@method		child toevoegen
	@param		htmlTag	child moet van het type htmlTag zijn
	*/
	public function addChild(htmlTag $iChild){
	
		$this -> childs[] = $iChild;
	
	}
	
	/*
	@method		meerdere child in één array toevoegen
	@param		array
	*/
	public function addRange(array $iChilds){
	
		foreach($iChilds as $child){
		
			$this -> addChild($child);
		
		}
	
	}
	/*
	@method		text zetten		<b> text </b>
	*/
	public function setText($iText){
	
		$this -> text = (string) $iText;
	
	}
	
	
	public function addText($iText){
	
		$this -> text .= (string) $iText;
	
	}
	
	/*
	@method		omzetten naar het type korte tag dus zonder afsluitende tag
	*/
	public function setToShortTag(){
	
		$this -> shortTag = true;
	
	}
	
	/*
	@method		renderen van het html gedeelte
	*/
	
	public function render(){
	
		$output = '<';
		$output .= $this -> tagName;
		// alle atributen aflopen en renderen
		foreach($this -> attributes as $key => $value){
			
			$output .= ' '.$key. '="' . $value . '"';
		}
		// korte tag hier afsluiten...
		if($this -> shortTag){
			$output .= '/>';
		}else{
		
			$output .= '>';
			$output .= "\n";
			// text laden
			if(isset($this -> text)){
				$output .= $this -> text;
			}
			
			// childs aflopen 
			foreach($this -> childs as $child){
				// childs op hun beurt renderen
				$output .= $child -> render();
			
			}
			
			// afsluitende tag renderen
			$output .= '</' . $this -> tagName .'>';
			
		}
		
		// output terug geven
		return $output . "\n";
	}


}

// end class


?>



voorbeeld:

[code=php]
$list = new htmlTag('ul');
$listItem = new htmlTag('li');

$listItem -> setText('ik ben een item');
$listItem -> setAttribute('class', 'test');

$list -> addChild($listItem);

echo $list -> render();

