i am getting html from the database, and want to output the html as text without the browser rendering the HTML.
I have unsuccessfully tried to set the content type to text/plain.
I have tried using the textarea but the code is not formatted.
i am getting html from the database, and want to output the html as text without the browser rendering the HTML.
I have unsuccessfully tried to set the content type to text/plain.
I have tried using the textarea but the code is not formatted.
You need to HTML escape the string before writing it out. How you do this depends on the language you are using.
You can also wrap it in <pre>
and <code>
tags to preserve the formatting.
E.g.,
<pre><code>
<div>my HTML markup</div>
</code></pre>
I have unsuccessfully tried to set the content type to text/plain.
That should work, though.
Alternatively, consider outputting the HTML with the HTML control characters escaped. In PHP, htmlentities($html)
would do the job.
I have unsuccessfully tried to set the content type to text/plain.
It should work. Something else is overriding this behaviour. What browser and URL are you using? MSIE is relying more on file extension in URL than on content type. Rather use name.txt
than name.html
. What response headers do you get? The webserver might have overriden it. You can use Firebug to get them all. Consult the server documentation how to set the proper headers for certain URL's.
Definitely go htmlentities route, maybe wrap in
<pre>... If that doesn't work, write something to go through the html and replace "<" with "< ;" (minus the space)