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?

Zack
  • 1,615
  • 18
  • 26
  • surely there is a better way than storing complete pages with php in the dabatase – Marko D Mar 04 '13 at 19:23
  • possible duplicate? [PHP eval issue with PHP + HTML code](http://stackoverflow.com/questions/2520344/php-eval-issue-with-php-html-code) – UnholyRanger Mar 04 '13 at 19:23

1 Answers1

4

Please take a look at eval().

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

Community
  • 1
  • 1
rationalboss
  • 5,330
  • 3
  • 30
  • 50
  • 2
    Be **very** careful with it. – Shoe Mar 04 '13 at 19:25
  • 1
    So careful that you **probably shouldn't use it**. – Mr. Llama Mar 04 '13 at 19:33
  • 1
    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. – thaJeztah Mar 04 '13 at 20:00