Echo EOT - 如何在其中使用循环和条件运算符?



我有一个关于代码的问题,如下所示:

echo <<<EOT 
<div class="quick-view-list nav">
How can i use loop or conditional operator here?
<a class="active" href="$similarProduct0">
<img src="$similarProductImg0" alt="Similar Product" width="100px" height="112px">
</a>
<a href="$similarProduct1">
<img src="$similarProductImg1" alt="Similar Product" width="100px" height="112px">
</a>
<a href="$similarProduct2">
<img src="$similarProductImg2" alt="Similar Product" width="100px" height="112px">
</a>
</div>
EOT;

甚至可能吗? 刚刚发现 EOT 和它非常适合我 - html 比这里长得多。

有好的一天!

你试过ob_startob_get_clean吗?你的代码可以这样写:

<?php // assuming php open here...

ob_start(); ?>
<div class="quick-view-list nav">
<?php
// do your conditional operator here....
?>
<a class="active" href="<?php echo $similarProduct0; ?>">
<img src="<?php echo $similarProductImg0; ?>" alt="Similar Product" width="100px" height="112px">
</a>
<a href="<?php echo $similarProduct1; ?>">
<img src="<?php echo $similarProductImg1; ?>" alt="Similar Product" width="100px" height="112px">
</a>
<a href="<?php echo $similarProduct2; ?>">
<img src="<?php echo $similarProductImg2; ?>" alt="Similar Product" width="100px" height="112px">
</a>
</div>
<?php 
echo ob_get_clean();

最新更新