Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write PHP code in PHP

Tags:

php

echo

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

like image 240
David Lorenzana Avatar asked Aug 05 '11 15:08

David Lorenzana


People also ask

How do I start PHP code?

If you want to run it, open any web browser and enter “localhost/demo. php” and press enter. Your program will run.

How can I write PHP code in notepad?

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.

How do you code in PHP?

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”.

How do I write a PHP document?

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.


5 Answers

<?php echo htmlentities('<?php echo \'aoeu\'; ?>'); ?>
like image 89
Paweł Avatar answered Nov 15 '22 20:11

Paweł


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.

like image 24
Karoly Horvath Avatar answered Nov 15 '22 18:11

Karoly Horvath


Try This

<<< is Heredoc

<?php

echo <<< EOF

<?php
echo <<< EOF
EOF;
?>

EOF;

?>
like image 25
Pheonix Avatar answered Nov 15 '22 19:11

Pheonix


<?php echo '&lt;?php echo \'aoeu\'; ?&gt;'; ?>

If you don't escape the '<' and '>' they will be printed as html tags.

like image 22
potNPan Avatar answered Nov 15 '22 18:11

potNPan


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"));
?>
like image 28
BARIS KURT Avatar answered Nov 15 '22 20:11

BARIS KURT