I have a blog that I manage that is mostly plain text with some HTML in it. When retrieving the text for that blog for display, I'm wanting to execute a line of PHP code within that text while hopefully avoiding the placement of PHP code in my database. I use MySQL.
In most cases, the PHP code would be something like <? include "phpfile.php"; ?>
. I would be using it to insert enhancements such as polls, slideshows, etc.
In the past, I've relied on iframes to hold the PHP file.
This is the blog text. <a id='marker'></a>
This is the second part of the blog text.
I've used "preg_replace()" to replace my marker (<a id='marker'></a>
) with the code for the iframe. This yields the following, which I echo with PHP to my page:
This is the blog text. <iframe src='phpfile.php'></iframe>
This is the second part of the blog text.
This works fine, but I'd like to be able to work without the constraint of having to guess the height and width of the iframe for the content that it holds.
In reading other threads/questions, I have considered these:
Inserting the PHP code into my database after the user has entered his blog (bad idea)
Using "eval" to somehow execute my PHP code after I replace my "marker" with the code? I'm not sure how I would do this in one step. I assume I would have to do something like the next approach. (I take it that "eval()" should be avoided as much as possible!!!)
Breaking the blog text into two parts (held in variables). I could do consecutive "echo" statements (one for each blog part) separated by an
include "phpfile.php";
. I'm not sure how memory intensive this is for my server - I'd be dealing with, say, ~50kb blocks of text.
Apart from that last approach, I feel like there's got to be a simpler way to insert the PHP code and execute it.
tia for any suggestions.