Tuesday, May 27, 2008

Include HTML within PHP

I did some testing and found that I can now include HTML documents inside of my existing documents. This ability to reuse code beats me copying and pasting all the time. Now a simple edit to a single HTML file that I have included in multiple files can affect multiple pages without me having to edit each.

I couldn't find a reliable way to do this in HTML, so I was forced to use PHP. That's okay, as I have a little PHP integrated into my site anyways. Here's an example of what I did to include other HTML files in my existing HTML files:

The PHP page that contains this directive must have a .php extension and the server must support PHP.

Why did I feel like sharing this tip?
I found it difficult to find a way to include HTML in HTML, so I figured that even one more example on the Internet might help someone.

No comments: