Using DirectPHP - intermixing PHP with HTML commands

Many people have posts questions in the forum why the following does not work with DirectPHP:

<table><tr>
<td>test1</td>
<td><?php echo $var1;?></td>
</tr></table>

DirectPHP uses PHP's plain old eval() function to process your PHP commands.

For those who have used eval(), the function can only process pure PHP commands. In a typical PHP page, you can freely intermix PHP and HTML commands. However, for the eval() function, it cannot process commands that include both PHP and HTML. It only understands PHP, not HTML.

Because DirectPHP uses eval(), so naturally it will not process codes with a intermix of PHP and HTML commands such as the codes above.

As a workaround, you can easily include HTML commands within PHP using the echo() function. So, to run the above code in DirectPHP, you can change the code to:

<?php
echo '<table><tr>
<td>test1</td>
<td>';
echo $var1;
echo '</td>
</tr></table>
?>';
Or simply:
<?php
echo "<table><tr>
<td>test1</td>
<td>$var1</td>
</tr></table>
?>";

Bottom Line: Make sure you use only pure PHP statements with DirectPHP. No HTML statements.

Add comment


Security code
Refresh