Reputation: 67
I have a .txt file containing code that I cannot change the contents of. And I need to display it in two ways.
One way is inside a div as selectable, copy-able type (currently done with:
<pre><?php include '/file_location.txt';?></pre>
).
The other way is as a direct link to the .txt file so such link can have it's address copied and emailed to someone, saved as..., or any other function one might like a direct link for. (So just like <a href="/file_location.txt">
basically.)
The issue is that when php including the text file into a div any <%> strings interfere with the original source text. I need to preserve the integrity of the original .txt files (so I can't go changing all the left carrots into <
).
So is there a good way to display the contents of the text file without issues with < >
and still maintain it's original integrity for sake of direct-linking?
EDIT:
I currently have two separate files performing this function, one with html encodings and the raw unedited .txt file. I'd really like to get these two displays working with just one file so that each new bit of source code doesn't need to be converted to an html-friendly version and adding just its .txt file will grant both view options.
EDIT 2:
Using <textarea>
instead of <pre>
will not interfere with the <
characters and i could CSS it to look how I want, but I don't like the idea of the user being able to resize it themselves.
Upvotes: 0
Views: 1346
Reputation: 538
I am using this for my php files. I think it will be usefull for you too.
<?php
highlight_file("test.php");
?>
edit: I tried on a html file and it worked.
Upvotes: 1
Reputation: 678
You can use
<?php echo htmlspecialchars(file_get_contents("file.txt")) ?>
instead of
<?php include '/file_location.txt';?>
to display special HTML characters from a text file.
Upvotes: 1
Reputation: 584
I would try to add <pre></pre>
at the beginning/end of your .txt
. I'm not sure if I fully understand your question, but I think this will not interfere with the <>
tags.
Upvotes: 0