How do I add PHP code/file to HTML(.html) files?
To add PHP code to an HTML file, you will need to use PHP tags. You can do this by enclosing your PHP code in
<!DOCTYPE html> <html> <head> <title>My PHP Page</title> </head> <body> echo "Hello, World!"; </body> </html>
Note that you will also need to save the file with a
.php extension, rather than
.html, in order for the PHP code to be executed by the server.
Alternatively, you can include a PHP file in an HTML file using the
require function. For example:
<!DOCTYPE html> <html> <head> <title>My PHP Page</title> </head> <body> include 'header.php'; <p>Some content</p> include 'footer.php'; </body> </html>
This will include the contents of the
footer.php files at the respective locations in the HTML file.