簡體   English   中英

Echo EOT - 我如何在其中使用循環和條件運算符?

[英]Echo EOT - how can i use loops and conditional operator inside it?

我有一個關於代碼的問題,如下所示:

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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM