1 Replies - 6089 Views - Last Post: 17 March 2013 - 10:23 AM Rate Topic: -----

#1 cartman182  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 22
  • Joined: 19-May 12

Echo HTML code as plain text.

Posted 17 March 2013 - 10:12 AM


Im trying to echo string from a file that I read from on the server.
So far I get the file open an reads it and seems to print line by line BUT my problem is the file that it reads is a text file with another websites code in it.
Looks almost like a basic website...ex:

and all the stuff inside etc etc.

So you can already see the problem here. Its going to print out an actual website titled Fart.
That's exactly what I don't want in this specific project.I want to echo the code lines one by one as it pulls it from the text file WITH PHP obviously.

So when I open my file it will be EXACTLY as it stands in the file and not HTML interpreted.

Now I have tried placing " " around every single string but it looks horrible and doesn't work anyway.
I have also tried breaking out with // and only 1 / as well, didn't work.
I have even tried <code></code> doesnt work anyway .

Here's the code for reading out of the file and echo it.

$handle = @fopen('code.txt', "r"); 
echo "'";
if ($handle) { 
   while (!feof($handle)) { 
		$x = $x+1;
       $lines[$x] = fgets($handle, 4096); 
	   //echo $lines[3],"\n";
	   echo '" ',$lines[$x],' "' ,"</br>";


This post has been edited by Dormilich: 17 March 2013 - 01:15 PM

Is This A Good Question/Topic? 0
  • +

Replies To: Echo HTML code as plain text.

#2 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6541
  • View blog
  • Posts: 26,474
  • Joined: 12-December 12

Re: Echo HTML code as plain text.

Posted 17 March 2013 - 10:23 AM

Use htmlentities() to convert all the < and > symbols, etc.:

echo '" ',$lines[$x],' "' ,"</br>";    // replace with

echo htmlentities($lines[$x]) . "</br>";

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1