Skip to content
Advertisement

How to include file marked in string in PHP?

I have a string, where user can add special mark, for example [include=example_file] and I would like to include “example_file.php” to the place where the mark is.

User’s text can be like:

JavaScript

I use this, to echo user’s text, now:

JavaScript

… and new output should be like:

JavaScript

What is the simplest way how to include files finded in those special marks?

Advertisement

Answer

Be careful of LFI attacks, but to achieve this, match the placeholder with regex, loop over it, use the value to load the file within a buffer, then replace the placeholder with the buffer.

Like this:

JavaScript

https://3v4l.org/qPqbI

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement