Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/311914-readfile-without-executing-html-code/
Share on other sites

Try

echo nl2br(htmlentities(file_get_contents('FILE')));

or

<div style='white-space: pre; font-family: monospace;'>
    <?=htmlentities(file_get_contents('FILE'))?>
</div>

 

Edited by Barand
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.