PHP包含功能不起作用

So I created a header.php file to store the basic html markup, but when I try to include it in my php code it just doesn't work. The output is as is like my code on my text editor.

<?php
include ("header.php");
?>

            <section class="main-container">
                <div class="main-wrapper">
                    <h2>HOME</h2>
                </div>
            </section>
        </body>
    </html>
  1. Try this syntax and pay attention to the opening tag:

    <?php include ("header.php"); ?>

  2. Make sure that file header.php is in the same directory as this file that you are coding and this file has an extension of .php

  3. Make sure that include is not disabled from php.ini (unlikely, unless someone deliberately did it)

  • Make sure all files have .php extension

    include('header.php');
    
  • Use include function script in the top of your php file

  • Filename must not be space

Check php opening tag. it should be <?php not like this ?php

<?php
 include ("header.php");
?>