Can HTML be embedded inside PHP “if” statement?



Yes, HTML can be embedded inside an ‘if’ statement with the help of PHP. Below are a few methods.

Using the if condition −

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

Using the if and else if conditions −

<?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; ?>

Embedding HTML inside PHP −

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

Advertisements