简体   繁体   中英

For a php include does the file that contains the include need the extension .php?

I have been trying to learn how to do a php include for an html website. The way I have been doing it has been typing the code for my header, navbar, and footer in php documents and then typing:

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

in the html file that I wish to include those documents (about.html) and so on. This has not been working for me even when testing with MAMP. Is there a better way to do this? I have heard that the file extension for the file that contains the include needs to be php. Thanks for suggestions!

This has not been working for me even when testing with MAMP. Is there a better way to do this?

You can include it by echoing out the HTML code in header.php and footer.php . Directly renaming the .html file to .php will not work.

I have heard that the file extension for the file that contains the include needs to be php.

Your file must be PHP, else you cannot include it. However, you can instruct the system to treat .html files as .php files using .htaccess . (Thanks @Fred -ii- for pointing out)

Source: http://php.net/manual/en/function.include.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM