0

I'm storing individual pages containing HTML and PHP in a database as plain text, like this:

<body>
<h1>Welcome</h1>
<?PHP $welcome = "Hello"; 
      echo $welcome; 
?>
<br />
</body>

And the desired result is to execute the PHP code mixed in with the plain text, so the above code would look like the following HTML to the browser:

<body>
<h1>Welcome</h1>
Hello<br />
</body>

I am using a function that simply ECHO's the plain text from the database to the page, so obviously, the PHP never gets treated as PHP.

How would you go about converting the PHP from being interpreted as plain text, to be executed as actual PHP code?

2
  • surely there is a better way than storing complete pages with php in the dabatase Commented Mar 4, 2013 at 19:23
  • possible duplicate? PHP eval issue with PHP + HTML code Commented Mar 4, 2013 at 19:23

1 Answer 1

4

Please take a look at eval().

This evaluates a PHP string as PHP code. But be very careful with this.

Sign up to request clarification or add additional context in comments.

3 Comments

Be very careful with it.
So careful that you probably shouldn't use it.
Please, please don't use this. It's really dangerous coding, just waiting for bad things to happen. If you need to ask a question like this, it means that you don't have a lot of knowledge of PHP and the consequences of coding like this. I'm not "bashing" you, just trying to prevent you from disasters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.