What are the best practices for including PHP scripts in HTML code?
When including PHP scripts in HTML code, it is best practice to use the `<?php ?>` tags to encapsulate your PHP code within the HTML file. This ensures that the PHP code is properly interpreted by the server before being sent to the client's browser. Additionally, it is important to separate PHP logic from HTML presentation to maintain clean and readable code.
<!DOCTYPE html>
<html>
<head>
<title>PHP in HTML</title>
</head>
<body>
<h1>Welcome <?php echo "User"; ?></h1>
<?php
// PHP logic to calculate and display something
$num1 = 10;
$num2 = 5;
$sum = $num1 + $num2;
echo "The sum of $num1 and $num2 is: $sum";
?>
</body>
</html>