Question

I am generating static HTML pages using output buffering using an include.

Is there any way to prevent certain parts of the php code being parsed? so that rather than having the output, the php is still intact?

Was it helpful?

Solution

According to the PHP documentation:

When a file is included, the code it contains inherits the variable scope of the line on which the include occurs. Any variables available at that line in the calling file will be available within the called file, from that point forward. However, all functions and classes defined in the included file have the global scope.

With that said, I don't think you can use include here. If you don't want PHP code to be parsed by the PHP interpreter, I would use file_get_contents() or something similar. This will allow you to fetch the file without any of the PHP code being parsed.

OTHER TIPS

If you want different parts of the html to have different caching policies then the way to acheive this is to split the script into parts which generate seperate HTML fragments then use another script to join the bits back together. There is a standard for doing this - ESI - but it can be a bit combersome (and is best implemented on a reverse proxy) compared with SSI

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top