[英]PHP spaces in HTML output when formatting code
Following code will produce unwanted whitespace between icons. 以下代码将在图标之间产生不需要的空白。
<div>
<img src="icon1.png" />
<img src="icon2.png" />
</div>
I need to keep image tags on single lines because I have some conditions in my .phtml file, it looks something like this: 我需要将图像标记保存在单行上,因为我的.phtml文件中有一些条件,它看起来像这样:
<div>
<?php if ($condition1) : ?>
<img src="icon1.png" />
<?php endif ?>
<?php if ($condition2) : ?>
<img src="icon2.png" />
<?php endif ?>
</div>
I don't want to have all code messed up on a single line. 我不希望所有代码都搞砸了。 Is there any solution for situations like this?
对于这样的情况有没有解决方案?
Apply font-size:0px;
应用
font-size:0px;
style to your div
. 你的
div
风格。
You may use echo to output parts of html code. 您可以使用echo输出html代码的部分内容。 You'll get something like this
你会得到这样的东西
<div>
<?php if (true) :
echo '<img src="icon2.png" />';
endif;
if (true) :
echo '<img src="icon2.png" />';
endif;
?>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.