public static function tag( $str, $wrapTag = 0, $attributes = [] ) {
		$selfclose = [ 'link', 'input', 'br', 'img' ];

		if ( !is_string( $str ) ) {
			return '';
		}
		if ( !is_string( $wrapTag ) ) {
			return $str;
		}
		$wrapTag = trim( strtolower( $wrapTag ) );
		$attrString = '';
		if ( is_array( $attributes ) ) {
			foreach ( $attributes as $attrKey => $attrVal ) {
				$attrKey = htmlspecialchars( trim( strtolower( $attrKey ) ), ENT_QUOTES );
				$attrVal = htmlspecialchars( trim( $attrVal ), ENT_QUOTES );
				$attrString .= " $attrKey=\"$attrVal\"";
			}
		}
		$return = "<$wrapTag$attrString";
		if ( in_array( $wrapTag, $selfclose ) ) {
			$return .= '/>';
		} else {
			$return .= ">" . htmlspecialchars( $str ) . "</$wrapTag>";
		}
		return $return;
	}
public static function tag( $str, $wrapTag = 0, $attributes = [] ) {
		$selfclose = [ 'link', 'input', 'br', 'img' ];

		if ( !is_string( $str ) ) {
			return '';
		}
		if ( !is_string( $wrapTag ) ) {
			return $str;
		}
		$wrapTag = trim( strtolower( $wrapTag ) );
		$attrString = '';
		if ( is_array( $attributes ) ) {
			foreach ( $attributes as $attrKey => $attrVal ) {
				$attrKey = htmlspecialchars( trim( strtolower( $attrKey ) ), ENT_QUOTES );
				$attrVal = htmlspecialchars( trim( $attrVal ), ENT_QUOTES );
				$attrString .= " $attrKey=\"$attrVal\"";
			}
		}
		$return = "<$wrapTag$attrString";
		if ( in_array( $wrapTag, $selfclose ) ) {
			$return .= '/>';
		} else {
			$return .= ">" . htmlspecialchars( $str ) . "</$wrapTag>";
		}
		return $return;
	}
public static function tag ( $ str , $ wrapTag = 0 , $ attributes = [ ] ) { $ selfclose = [ 'link' , 'input' , 'br' , 'img' ] ; if ( ! is_string ( $ str ) ) { return '' ; } if ( ! is_string ( $ wrapTag ) ) { return $ str ; } $ wrapTag = trim ( strtolower ( $ wrapTag ) ) ; $ attrString = '' ; if ( is_array ( $ attributes ) ) { foreach ( $ attributes as $ attrKey => $ attrVal ) { $ attrKey = htmlspecialchars ( trim ( strtolower ( $ attrKey ) ) , ENT_QUOTES ) ; $ attrVal = htmlspecialchars ( trim ( $ attrVal ) , ENT_QUOTES ) ; $ attrString .= " $attrKey=\"$attrVal\"" ; } } $ return = "<$wrapTag$attrString" ; if ( in_array ( $ wrapTag , $ selfclose ) ) { $ return .= '/>' ; } else { $ return .= ">" . htmlspecialchars ( $ str ) . "</$wrapTag>" ; } return $ return ; }
Primitive html builder

Based on similar methods in krinkle/toollabs-base,
and Html::element in MediaWiki.

@param string $str Content (text or HTML)
@param string|int $wrapTag Name of HTML Element (tagName)
@param array $attributes [optional]
@return string HTML
Primitive html builder