Skip to content

Instantly share code, notes, and snippets.

@tamagokun
Created November 23, 2011 18:39
Show Gist options
  • Save tamagokun/1389498 to your computer and use it in GitHub Desktop.
Save tamagokun/1389498 to your computer and use it in GitHub Desktop.
Quick php util for creating HTML
<?php
class HTML
{
public static function __callStatic($tag,$args)
{
$options = array_shift($args);
$content = ($args)? array_shift($args) : "";
return self::element($tag,$options,$content);
}
private static function element($tag,$options,$content)
{
$attrs = "";
foreach($options as $attr=>$option) $attrs .= "$attr=\"$option\" ";
return (self::self_closing($tag))? "<$tag $attrs/>" : "<$tag $attrs>$content</$tag>";
}
private static function self_closing($tag)
{
$inline = array("link","meta","img","input","br","hr");
return in_array($tag,$inline);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment