问题描述
假设我有2种情况:
<?php
print("html code goes here");
?>
v.s
<?php
?>
html codes goes here
<?php
?>
第一种情况下PHP解释器的性能是否会比第二种情况差? (由于打印功能内部处理的额外开销).
Would the performance for PHP interpreter in the first case be worse than the second one? (Due to the extra overhead of processing inside print function).
那么,有没有人建议将html代码插入php代码?
So, does anyone have a recommended way to insert html codes inside php codes?
推荐答案
完全不要那样做!使用像聪明,因此您可以将逻辑与显示代码分开.它还允许您引入可以使用html且可能根本不了解php的设计器. Smarty模板读起来更像HTML,而不是PHP,这在与设计师打交道时会产生很大的不同.
Don't do it that way at all! Use a templating system like Smarty so you can separate your logic from your display code. It also allows you to bring in a designer that can work with html and might not know php at all. Smarty templates read more like HTML than PHP and that can make a big difference when dealing with a designer.
此外,您不必担心设计师在查找/替换时会弄乱您的代码!
Also, you don't have to worry about your designer messing with your code while doing a find/replace!
更好的选择是使用 Django 或 Rails 清楚地描述了代码/模板设置,但是如果您不能做到这一点(廉价的托管解决方案),则至少要使用模板.我不知道smarty是否对PHP最好,但是它远比您提出的两种解决方案都要好.
Better yet would be to go to a setup like Django or Rails that has clearly delineated code/template setup, but if you can't do that (cheap hosting solutions) then at least use templating. I don't know if smarty is the best thing for PHP, but its far better than both solutions you are proposing.
这篇关于将html代码嵌入php代码的推荐方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!