Created
February 24, 2016 21:15
-
-
Save ibourgeois/76f01337512e355c1eb5 to your computer and use it in GitHub Desktop.
PHP HTML Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class HTML { | |
public function __construct() { | |
} | |
public function doctype() { | |
return '<!DOCTYPE html>'; | |
} | |
public function open($tag, $attributes = NULL) { | |
$sct = array( | |
'area', 'input', | |
'base', 'keygen', | |
'br', 'link', | |
'col', 'meta', | |
'command', 'param', | |
'embed', 'source', | |
'hr', 'track', | |
'img', 'wbr' | |
); | |
if (in_array($tag, $sct)) { | |
$html = '<'.$tag; | |
if ($attributes != NULL) { | |
foreach ($attributes as $attribute => $parameter) { | |
$html .= ' '.$attribute.'="'.$parameter.'"'; | |
} | |
$html .= ' />'; | |
return $html; | |
} else { | |
$html .= ' />'; | |
return $html; | |
} | |
} else { | |
$html = '<'.$tag; | |
if ($attributes != NULL) { | |
foreach ($attributes as $attribute => $parameter) { | |
$html .= ' '.$attribute.'="'.$parameter.'"'; | |
} | |
$html .= '>'; | |
return $html; | |
} else { | |
$html .= '>'; | |
return $html; | |
} | |
} | |
} | |
public function close($tag) { | |
return '</'.$tag.'>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment