Garrett Stelly.com

Title

Abrupt end to a PHP tag

Breaking out of PHP code blocks to write some HTML

Did you know that you can just break in and out of writing PHP? For example, If you're writing an if(){}else{} statement, after the opening brackets, you can close the tag, write some HTML (rather than using echo), and simply open a new tag and continue on where you left off. Why, I've even done it within the content of this paragraph you're reading right now!


  <html>
<head>
  <title>Breaking free of PHP</title>
</head>
<body>
  <h1>Abrupt end to a PHP tag</h1>
  <h2>Breaking out of PHP code blocks to write some HTML</h2>
  <p>Did you know that you can just break in and out of writing PHP?  For example, If you're writing an <code>if(){}else{}</code> statement, after the opening brackets, you can close the <code><?php ?></code> tag, write some
<?php if(rand(0,1)){ ?>
  HTML
<?php } else{ ?>
  HTML code
<?php } ?>
  (rather than using <code>echo</code>), and simply open a new <code><?php ?></code> tag and continue on where you left off.  Why, I've even done it within the content of this paragraph you're reading right now!</p>
</body>
</html>

You can read up more on developing web pages with PHP integration at php.net