How to embedded PHP code in HTML code?

In order to embedded PHP code, the tags <?php and ?> are used. The <?php is the opening command, whereas ?> is the closing command. The code is embedded directly into HTML code. This is possible because PHP has been designed to directly interact with HTML.

Sample of PHP code in HTML Code:

<title>Encoding PHP in HTML</title>
This is normal HTML code
               // php code here
               for($i=1;$i<=5;$i++){ ?>
<li>Menu Item <?php echo $i; ?></li>
Back into normal HTML

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.