I was trying to make my life easier making a class or something that would create HTML tags in a faster way. I ended up with something that I wouldn't consider the best practice. Take a look:
/**
* Add HTML to the page
*
* Add HTML to the page based on arrays with the tag names. It's gonna open and close the tags.
*
* @param array tags The name of the tags
* @param array attributes The attributes of the tags if you want
* @param array The elements you want inside the tags
*/
function addHtml($tags = null, $attributes = null, $innerHtml = null)
{
for($i = 0; $i < count($tags); $i++) {
// Opens the tag
echo '<' . $tags[$i];
// If there're attribures, show them and close
// If not, just closes the tag
echo !empty($attributes) ? ' ' . $attributes[$i] . '>' : '>';
// Show something you wanna put inside the tag. Another tag, text, anything
echo $innerHtml[$i];
// Closes the tag
echo '</' . $tags[$i] . '>';
}
}
Is there someone with a better way of doing it?