Search code examples
phphtmlembedembedding

How do I run PHP in HTML?


If I have a file, file.php, in the same directory as index.html:

file.php:

<?php
echo "<body><img src=\"hi.jpg\" /><br /><p>I was here</p>"
?>

index.html:

<html>
<head></head>
<!-- I want to enter the PHP in file.php here --></body>
</html>

How do I put file.php in index.html?


Solution

  • Rename index.html to index.php, and fill it with the following:

    <html>
    <head></head>
    <?php
    require('./file.php');
    ?>
    </html>