Créditos para o autor Max Ferreira
Segue o código e exemplo de utilização:
<?php // PHP Compatibility Code if (!function_exists('file_put_contents')) { function file_put_contents($filename, $data) { $file = fopen($filename, 'wb'); $return = fwrite($file, $data); fclose($file); return $return; } } /** * Executes the PHP code sent as argument and return the generated string * Code by: Max Ferreira * * @access public * @param string $phpCode PHP Code to be executed * @return string Generated output */ function getPHPOutput($phpCode) { $tmpFileName = tempnam('/tmp', 'PHP_INCLUDE'); file_put_contents($tmpFileName, $phpCode); ob_start(); include $tmpFileName; $result = ob_get_contents(); ob_end_clean(); @unlink($tmpFileName); return $result; } ?>
Exemplo de utilização:
<?php require_once "func.getPHPOutput.php"; $text = 'lá vai o texto: <?php echo "texto interpretado pelo php";?'.'>'; echo getPHPOutput($text); ?>
Espero ter ajudado!
[]s,