Taapo Taapo - 4 months ago 14
PHP Question

How to return raw php code?

I have this code for example:

ob_start();
echo "hello there";
$output = ob_get_contents();
return $output;


When I run it, I get back:

hello there


But how can I get back

echo "hello there";


Is there a way to do this easily?

Answer

To output arbitrary text as-is you can close the PHP script and then reopen it. Anything between the closing and opening tags are output as-is

ob_start();
?>echo "hello there";
<?php
$output = ob_get_contents();
return $output;
Comments