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

问题描述 投票:-4回答:1

我需要将信息从数据库打印到html模板,但我读过有最佳实践,而不仅仅是打印所需的html。有点模板填充物。 谢谢。

编辑:我发现框架Smarty,所以,从一个带有可变字段的html模板,我可以填写像这个$smarty->assign('htmlVar', $data);的字段,然后加载它。 再次感谢。

php html
1个回答
2
投票

A couple of alternative methods (of many)

我们可以使用DOMDocument::createElement和许多相关方法来构建一个可以输出的DOM。

此函数创建类DOMElement的新实例。除非与(例如)DOMNode::appendChild()一起插入,否则此节点不会显示在文档中。

Another alternative回应HTML的字符串,是使用类似的东西:

<?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; ?>
© www.soinside.com 2019 - 2024. All rights reserved.