PHP:如何隐藏/显示HTML块 [英] PHP: How to hide/display chunks of HTML
问题描述
隐藏或显示< div>
/ < asp:Panel>
s非常简单,但在PHP中,我所能做的就是将HTML放入 echo
语句。这使得HTML非常难以阅读,难以维护,整个文件看起来相当混乱。
我认为必须有更好的隐藏或显示块的方式的HTML而不必涉及 echo
语句,但是我找不到任何解释如何的在线文档。
感谢任何提示,建议或指向这个级别的问题的良好PHP资源的链接。
您应该为了获得更好的可读性,为模板使用特定的语言形式。除了使用echo外,您还可以在<?php?>
标记(从不使用<??>
,这可能会引起误解)。
另外建议使用 if():
而不是 if(){
,例如:
< body>
<?php if(true):?>
< p>这是真的< / p>
<?php endif; ?>
< / body>
参考文献:
I'm hoping someone can help with this very newbie question. I've just come from an ASP.Net environment where it was easy to hide or show chunks of HTML. For example: Different stages of a form, depending on what the user had entered.
Hiding or showing <div>
/<asp:Panel>
s was very simple, but in PHP all I can think to do is put my HTML into an echo
statement. This makes the HTML very difficult to read, difficult to maintain and the whole file looks rather messy.
I'm positive there must be a better way of hiding or showing chunks of HTML without having to involve an echo
statement, but I can't find any online documentation that explains how.
Thanks for any tips, advice or links to good PHP resources for this level of problem.
Considering PHP as an embedded language you should, in order to get better readability, use the specific language forms for the "templating".
Instead of using echo you could just write the HTML outside the <?php ?>
tags (never use <? ?>
which could be misleading).
Also it is suggested to use if () :
instead of if () {
, for example:
<body>
<?php if (true) : ?>
<p>It is true</p>
<?php endif; ?>
</body>
References:
这篇关于PHP:如何隐藏/显示HTML块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!