html - Running php scripts within echo

one text

We're working on CDN website that can load more than just images, specially we want to host code and allow it to be rendered with or without php and other backends directly; however there is one problem.

In PHP, when we echo the contents of a user submission that contains php code in it of it's self, it prints it out instead of doing whats inside, can anyone think of way we could make the PHP run? We can't really think of anything.

Perhaps we should generate a temporary file and put the content in there then use the require function? I'm not sure really. Any help would be great.

For instance, here is some demo content to work with while answering the question.

User Submission to CDN

<h1>My Site! :)</h1>
<p>Good morning,</p>
<p><?php
echo $_COOKIE['name'];
?></p>

The Loading Process

(database code)
$usercontent = $row['sourcecode'];

if($requestedraw) {
   header("content-type: text/json");
   if($runphpinside) {
      (Perhaps a "runphpfirst" function for parsing it?)
      echo runphpfirst($usercontent);
   } else {
      echo $usercontent;
   }
} else {
   header("content-type: text/html");
   echo runphpfirst($usercontent);
}

Current Result - From Browser

<h1>My Site! :)</h1>
<p>Good morning,</p>
<p><?php
echo $_COOKIE['name'];
?></p>

Expected Result - From Browser

<h1>My Site! :)</h1>
<p>Good morning,</p>
<p>ExampleUsername</p>

~ N.

Source