/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* creates an html element, like in js */ class html_element { /* vars */ var $type; var $attributes; var $self_closers; /* constructor */ { $this->self_closers = $self_closers; } /* get */ function get($attribute) { return $this->attributes[$attribute]; } /* set -- array or key,value */ function set($attribute,$value = '') { { $this->attributes[$attribute] = $value; } else { } } /* remove an attribute */ function remove($att) { { } } /* clear */ function clear() { } /* inject */ function inject($object) { { $this->attributes['text'].= $object->build(); } } /* build */ function build() { //start $build = '<'.$this->type; //add attributes { foreach($this->attributes as $key=>$value) { if($key != 'text') { $build.= ' '.$key.'="'.$value.'"'; } } } //closing { $build.= '>'.$this->attributes['text'].'</'.$this->type.'>'; } else { $build.= ' />'; } //return it return $build; } /* spit it out */ function output() { echo $this->build(); } }
URL: http://davidwalsh.name/create-html-elements-php-htmlelement-class