Ho questa classe Html il problema e che non funziona come dovrebbe, qualcuno sa come mai ???
PHP:
class Html {
private $tag = '', $open_tag = '', $close_tag = '';
public function tag( $tag, $value, $attr = '' ){
if( is_object( $value ) ){
$this->open_tag .= '<'.$tag.$this->attr( $attr ).'>';
$this->close_tag .= '</'.$tag.'>';
}else{
if( $this->open_tag != '' ){
$this->tag .= $this->open_tag;
$this->open_tag = '';
}
$this->tag .= '<'.$tag.$this->attr( $attr ).'>'.$this->value( $value ).'</'.$tag.'>';
if( $this->close_tag != '' ){
$this->tag .= $this->close_tag;
$this->close_tag = '';
}
}
return $this;
}
private function attr( $attr ){
if( empty( $attr ) ) return;
if( is_array( $attr ) ){
foreach( $attr as $key => $value )
$a[] = $key.'="'.$value.'"';
return ' '.implode( ' ', $a );
}
return $attr;
}
private function value( $value ){
return is_callable( $value ) ? call_user_func( $value ) : $value;
}
public function exe(){
$tag = $this->tag;
$this->tag = '';
return $tag;
}
}
$html = new Html();
echo $html->tag( 'html',
$html->tag( 'body',
$html->tag( 'header',
$html->tag( 'h1', 'Header' )
)->tag( 'footer',
$html->tag( 'h1', 'Footer' )
)
)
)->exe();