- 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)