I have this testfile.php where I try passing through a code block including the PHP-Tags.
But when I do so the result will end up in a comment.
I haven't found it in the documentation and obviously PHP runs on Apache otherwise I wouldn't get the class working.
I want to know: Why is the code commented out and how can this be solved in an appropriate way?
Update:
Using eval() a working solution is provided by Asad Raza, yet it is using eval().
eval("?>". $string);
I have html surrounding the code (a mixed php-html page).
In real life am fetching the whole batch from a database table.
I need to pass it through exactly as is and eval won't be considered to be the best option as I think there should be a cleaner solution.
The result should not be a simple print of plain text, but the executed code e.g. like the instantiation of a class.
<?php
class Test
{
public function __construct()
{
}
public function getPHPCodeOne()
{
return '<?php echo "Hi, I want to be PHP-Code"; ?>';
}
public function getPHPCodeTwo()
{
return '<?php $fooClass = new className(); echo $fooClass->barMethod(); ?>';
}
}
$test = new Test();
echo $test->getPHPCodeOne();
echo $test->getPHPCodeTwo();
Would result in
<!--?php echo "Hi, I want to be PHP-Code"; ?-->
<!--?php $fooClass = new className(); echo $fooClass--->"barMethod(); ?>"
But should result in:
Hi, I want to be PHP-Code
I'am the Output of my flexible fooClass->barMethod.