/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php /** * Create an element */ class Element { private $type; private $attributeArray; private $innerHtml; /** * Constructor * * @param <type> $type * @param <type> $attributeArray * @param <type> $unaryTagArray */ { foreach($attributeArray as $attribute => $value) { $this->setAttribute($attribute, $value); } return $this; } /** * Get one of the element's attributes * * @param <type> $attribute * @return <type> */ public function getAttribute($attribute) { return $this->attributeArray[$attribute]; } /** * Set an array, can pass an array or a key, value combination * * @param <type> $attribute * @param <type> $value */ function setAttribute($attribute, $value = "") { $this->attributeArray[$attribute] = $value; } else { } return $this; } /** * Remove an attribute from an element * * @param <type> $attribute */ function removeAttribute($attribute) { } return $this; } /** * Clear all of the element's attributes */ function clearAttributes() { return $this; } /** * Insert an element into the current element * * @param <type> $object */ function insert($object) { $this->innerHtml .= $object->build(); } return $this; } /** * Set the innerHtml of an element * * @param <type> $object * @return <type> */ function update($object) { $this->innerHtml = $object; return $this; } /** * Builds the element * * @return <type> */ function build() { // Start the tag $element = "<".$this->type; // Add attributes foreach($this->attributeArray as $key => $value) { $element .= " ".$key."=\"".$value."\""; } } // Close the element $element.= ">\n".$this->innerHtml."\n</".$this->type.">\n"; } else { $element.= " />\n"; } return $element; } /** * Echoes out the element * * @return <type> */ function __toString() { return $this->build(); } }