Skip to content

Instantly share code, notes, and snippets.

@ibourgeois
Created February 24, 2016 21:15
Show Gist options
  • Save ibourgeois/76f01337512e355c1eb5 to your computer and use it in GitHub Desktop.
Save ibourgeois/76f01337512e355c1eb5 to your computer and use it in GitHub Desktop.
PHP HTML Class
<?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