如何将动态PHP代码插入从MYSQL检索的文章中?

I have spent the past 2 days trying to figure this out and came to a conclusion that eval() should not be used due to security issues.

My situation: I have an article stored in MYSQL database in plain text and i would like to add a dropdown menu in the middle of the article as the article is being displayed on the website. This drop down would need to be populated from a database also and the records change everyday thus the need to be dynamic. I would also like to add the code for ad's to certain places within the article.

What is the preferred way?

You could add to the article a keyword (for example : {dropdown}) who triggers the dropdown, then use str_replace() to replace {dropdown} by your dropdown code :

<?php
$article = 'Lorem ipsum dolor sit amet. {dropdown} Aliquam tincidunt leo non elementum.';

$dropdownCode = "Here's the dropdown code.";

$article = str_replace('{dropdown}', $dropdownCode, $article);

print $article;

/* Output : 
Lorem ipsum dolor sit amet. Here's the dropdown code. Aliquam tincidunt leo non elementum. 
*/