31 August 2018

How to Write PHP code and HTML code within a same file

  • A PHP file can have both PHP code and HTML code together.
  • Any HTML code written outside of PHP <?php //php code here… ?> Code is ignored by the PHP parser which allows PHP files to have PHP code and HTML code in a same file.
  • A PHP file must have “.php” extension. 
  • Sample “index.php” file code is given bellow:

  •  1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    <!DOCTYPE html>
    <html>
    <head>
    <title>Web Page Title</title>
    </head>
    <body>
    <?php
     echo "<h1>HTML Code inside PHP code </h1>";
    ?>
    <h1>This is a Heading</h1>
    <?php
     echo "Today's Date is ".date("d-m-y");
    ?>
    <p>This is a paragraph.</p>
    
    </body>
    </html> 
    
  • Output of above code:
  • HTML Code inside PHP code

    This is a Heading

    Today's Date is 01-09-18
    This is a paragraph.
    
    

# Book on PHP:


Learning PHP, MySQL & JavaScript: With jQuery, CSS & HTML5 (Learning PHP, MYSQL, Javascript, CSS & HTML5)

1 comment:

  1. Hello there! I could have sworn I've been to this web site before but after browsing through a few of the articles I realized it's new to me. Regardless, I'm definitely delighted I discovered it and I'll be bookmarking it and checking back often!

    ReplyDelete

Featured Post

How to Write PHP code and HTML code within a same file

A PHP file can have both PHP code and HTML code together. Any HTML code written outside of PHP <?php //php code here… ?> Code is ig...

Popular Posts