Include repeating HTML snippet

I basically have divon my site that always has the same material. However, this is divnot available on all pages, so I will not use a dynamic web template. I was wondering if PHP can get the code from a document on the server and paste it into a div?

Example:

<div id="section...

then my text file contains

<p>hello</p>

Basically, I want PHP to put it in a div when the user sees it.

If this is a more reasonable way to achieve this, I will also be open to him.

thank

+3
source share
3 answers

Just a include()file. The interpreter will switch from PHP mode back to HTML mode, displaying everything that it encounters.

+5

?

<div id="section"><?php include ('path-to-your-file') ?></div>
+2

, div, .

How to control whether this is included or not depends on how your website is created.

For example, if you have database entries for your pages, add a column with a name includediv(perhaps you will get a better name ...), and if it is true, you will include the file otherwise.

+1
source

Source: https://habr.com/ru/post/1746226/


All Articles