哪个是用PHP打印html的最佳方法?

I need to print info from a database to a html template, but i've read that there are best practices rather than just printing the html required. Kinda a template filler.
Thanks.

Edit: i found the framework Smarty, so, from an html template with variable fields, I can fill the fields like this $smarty->assign('htmlVar', $data); and then load it.
Thanks, again.

A couple of alternative methods (of many)

We can use DOMDocument::createElement and many related methods to build a DOM which can then be output.

This function creates a new instance of class DOMElement. This node will not show up in the document unless it is inserted with (e.g.) DOMNode::appendChild().

Another alternative to echoing strings of HTML, is to use something like:

<?php if ( condition ): ?>
<p>This will be output</p>
<?php elseif ( other_condition ): ?>
<p>This will be output instead</p>
<?php else: ?>
<p>Or this</p>
<?php endif; ?>