How can I write PHP code in PHP? I want to do this, but it doesn't work:
<?php echo '<?php echo \'aoeu\'; ?>'; ?>
Hope someone can give me a hint,
Many thanks
If you want to run it, open any web browser and enter “localhost/demo. php” and press enter. Your program will run.
In Notepad, add . php to the end of the filename and enclose in double quotations. This ensures the file will not be converted into a basic text file by Notepad.
In order to start PHP, MySQL, PHPMyAdmin and Apache in a single attempt, XAMPP should be installed. Scroll over to XAMPP for Windows and download should begin shortly. Click the .exe file to start the installation procedure. Select the components which you want to install and click “Next”.
PHP Write to File - fwrite() The fwrite() function is used to write to a file. The first parameter of fwrite() contains the name of the file to write to and the second parameter is the string to be written.
<?php echo htmlentities('<?php echo \'aoeu\'; ?>'); ?>
If you output some complex code definitely use a template engine like smarty.. otherwise your code will look a complete mess.
I once patched the propel ORM which does output PHP code without using a template engine. It generates all the model classes based on the XML configuration files. Their code was a big mess. Don't do it.
Try This
<<< is Heredoc
<?php
echo <<< EOF
<?php
echo <<< EOF
EOF;
?>
EOF;
?>
<?php echo '<?php echo \'aoeu\'; ?>'; ?>
If you don't escape the '<' and '>' they will be printed as html tags.
You can use highlight_string or highlight_file if you use highligh_file you have to indicate php file that you want to show
<?php
highlight_string('<?php echo\'hello\' ?>');
highlight_file("D:\local\ajax_bottom.php");
?>
or you can combine both which the best solution for me:
<?php
$string=highlight_file("D:\local\hatirlaticilar\Adminn\autocomplete\gethint.php");
highlight_string("$string");
?>
or you can combine in a different way:
<?php
highlight_string(highlight_file("D:\local\hatirlaticilar\Adminn\autocomplete\gethint.php"));
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With