PHP code is written inside <?php ... ?>
tags. The PHP interpreter processes this code on the server, and the output is sent as HTML to the browser.
<?php
echo "Hello, World!";
?>
🔹 Explanation:
<?php
→ Starts the PHP script.echo
→ Outputs text to the browser."Hello, World!"
→ Text inside quotes is displayed.?>
→ Ends the PHP script (optional if the file contains only PHP code).
PHP can be embedded inside an HTML document.
<!DOCTYPE html>
<html>
<head>
<title>PHP Example</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>Today’s date is: <?php echo date("Y-m-d"); ?></p>
</body>
</html>
🔹 Explanation:
<?php echo date("Y-m-d"); ?>
outputs the current date inside a paragraph.
Each PHP statement must end with a semicolon (;
).
<?php
echo "Hello, World!";
echo "Welcome to PHP!";
?>
✔ Correct: Each statement ends with ;
.