HTML 可以嵌入 PHP “if” 語句中嗎?


沒錯,藉助 PHP,HTML 可以嵌入到“if”語句中。以下是幾種方法。

使用 if 條件 −

<?php if($condition) : ?>
   <a href="website_name.com">it is displayed iff $condition is met</a>
<?php endif; ?>

使用 if 和 else if 條件 −

<?php if($condition) : ?>
   <a href=" website_name.com "> it is displayed iff $condition is met </a>
<?php elseif($another_condition) : ?>
   HTML TAG HERE
<?php else : ?>
   HTML TAG HERE
<?php endif; ?>

在 PHP 中嵌入 HTML −

<?php
   if ( $condition met ) {
      ?> HTML TAG HERE
<?php;
}
?>

更新於: 2020 年 4 月 6 日

5K+ 瀏覽次數

開啟您的 職業生涯

完成課程後獲得認證

開始課程
廣告
© . All rights reserved.