/**
 * Generates an HTML Node
 * @param string $name
 * @param boolean $short
 * @param array $attributes
 * @param string $content
 * @return Ambigous <NULL, string>
 */
function createTag($name, $short = false, $attributes = null, $content = null) {
    $tag = null;

    if (!$short) {
        $tag = sprintf("<%s%s>%s</%s>", $name, array_to_html_attributes("=", $attributes), $content, $name);
    } else {
        $tag = sprintf("<%s%s/>", $name, array_to_html_attributes("=", $attributes));
    }

    unset($name, $short, $attributes, $content);

    return $tag;
}

see for array_to_html_attributes:  http://blog.teknober.com/2011/04/13/php-array-to-html-attributes/