phppup Posted December 22, 2020 Share Posted December 22, 2020 In a PHP file [php_one.php], I wrote some PHP code that contained a form. I used ECHO to write the HTML inside of the PHP tags. On another PHP page [php_two.php], I wanted to show the code that was used to create the first page [php_one.php]. My first effort provided an interesting result, since the PHP code was readable. However, all HTML code was visible in its executed form. There was an actual input field and a submit button (not the code used to produce them) in the context of my coding. I have tried using: file_get_contents("FILE") $array = file("FILE") readfile("FILE") All results were similar and carried the same problem. How can I view code so that even the HTML is visible as code? Quote Link to comment https://forums.phpfreaks.com/topic/311914-readfile-without-executing-html-code/ Share on other sites More sharing options...
gw1500se Posted December 22, 2020 Share Posted December 22, 2020 One way is to translate all <> characters to < and > respectively. You may need to wrap it in <pre>...</pre> tags to format it. Quote Link to comment https://forums.phpfreaks.com/topic/311914-readfile-without-executing-html-code/#findComment-1583332 Share on other sites More sharing options...
Barand Posted December 22, 2020 Share Posted December 22, 2020 (edited) Try echo nl2br(htmlentities(file_get_contents('FILE'))); or <div style='white-space: pre; font-family: monospace;'> <?=htmlentities(file_get_contents('FILE'))?> </div> Edited December 22, 2020 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/311914-readfile-without-executing-html-code/#findComment-1583333 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.