PHP Include for HTML?

前端 未结 7 2050
小蘑菇
小蘑菇 2020-12-02 23:22

I have a navigational bar, an image, and a heading that I\'ll be including in every page of my website, so I wanted to use php include to refer to this code in several pages

7条回答
  •  心在旅途
    2020-12-02 23:49

    You don't need to be echoing the info within the php file. A php include will automatically include any HTML within that file.

    Make sure you're actually using a index file with a .php extension, .html won't work with php includes. (Unless you're telling your server to treat .html files otherwise)

    Make sure your paths are correctly set up. From your description, the way you've set it up your header.php/navbar.php/image.php files should be in your root directory. So your root directory should look like this:

    index.php
    navbar.php
    image.php
    header.php

    Otherwise if those PHP files are in a folder called /includes/, it should look like so:

提交回复
热议问题