By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,742 Members | 793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,742 IT Pros & Developers. It's quick & easy.

Hot to output HTML Source Code

P: n/a
Hello.

I want to show HTML source code in my browser (for debugging
purposes). Which tag/formatting di i have to use to tell the browser
not to render the code but display it as pure text?

E.g.

I want
<p>Hello World</p>
to be displayed in the browser.

I have tested <code><p>Hello world</p></code>, but that doesn't work.

Waht can I do? Thanks in advance
Martin
Jul 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a


Martin Ernst wrote:
I want to show HTML source code in my browser (for debugging
purposes). Which tag/formatting di i have to use to tell the browser
not to render the code but display it as pure text?

E.g.

I want
<p>Hello World</p>
to be displayed in the browser.

I have tested <code><p>Hello world</p></code>, but that doesn't work.

Waht can I do? Thanks in advance


Escape the tag characters < and >, as in
&lt;p&gt;A paragraph.&lt;/p&gt;

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2

P: n/a
Martin Ernst <m.*****@connect-wa.de> wrote:
I want to show HTML source code in my browser (for debugging
purposes). Which tag/formatting di i have to use to tell the browser
not to render the code but display it as pure text?
If you want the whole page to be seen as code then you can configure
your server to serve it as text/plain rather than text/html. However,
IE will still parse it as HTML; better browsers will display it as
plain text.
I want
<p>Hello World</p>
to be displayed in the browser.

I have tested <code><p>Hello world</p></code>, but that doesn't work.


That tells the browser that the enclosed content is code, which is a
good thing. However, it doesn't tell the browser tos top parsing it
for HTML tags.

You need to convert all the isntances of < to &lt;
In some cases you also need to convert > to &gt; and wether you do so
in all cases is up to you.

&lt;p&gt;Hello World&lt;/p&gt;

(You'll also need to convert & to &amp; so that &copy; would be
&amp;copy; and would be displayed as &copy; rather than as teh
copyright symbol.)

There's also the very old, <xmp></xmp> element but that's been
obsolete since HTML 2, isn't supported by all browsers and really can
not be recommended.

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <st***@pugh.net> <http://steve.pugh.net/>
Jul 20 '05 #3

P: n/a
Steve Pugh <st***@pugh.net> schrieb:

You need to convert all the isntances of < to &lt;
In some cases you also need to convert > to &gt; and wether you do so
in all cases is up to you.

&lt;p&gt;Hello World&lt;/p&gt;


As it seems, I have no choice. Thanks for your answers.

Martin
Jul 20 '05 #4

P: n/a
Martin Ernst wrote:
Hello.

I want to show HTML source code in my browser (for debugging
purposes). Which tag/formatting di i have to use to tell the browser
not to render the code but display it as pure text?


Replace the < and > characters with their respective entities (&lt; and
&gt;).
Jul 20 '05 #5

P: n/a
Martin Ernst wrote:
Hello.

I want to show HTML source code in my browser (for debugging
purposes). Which tag/formatting di i have to use to tell the browser
not to render the code but display it as pure text?

E.g.

I want
<p>Hello World</p>
to be displayed in the browser.

I have tested <code><p>Hello world</p></code>, but that doesn't work.


Do you have PHP ?

then you could use:

<?php
echo htmlentities(<p>Hello World</p>);
?>

should work...

Jul 20 '05 #6

P: n/a
Karsten Tholema wrote:

[snip]
<?php
echo htmlentities(<p>Hello World</p>);
?>


Getting a bit OT here now, but that should be:

<?php
echo htmlentities('<p>Hello World</p>');
?>
--
Jim Dabell

Jul 20 '05 #7

P: n/a
Martin Ernst <m.*****@connect-wa.de> wrote:
I want to show HTML source code in my browser (for debugging
purposes).


What debugging? Which software would you debug that way?

(Just a rhetoric question. Usually people ask the question when they wish to
tell others which HTML code they should use. But it would be reasonable to
expect you to know HTML yourself before trying to teach it to others.)

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html

Jul 20 '05 #8

P: n/a

"Martin Ernst" <m.*****@connect-wa.de> wrote in message
news:f5********************************@4ax.com...
Hello.

I want to show HTML source code in my browser (for debugging
purposes). Which tag/formatting di i have to use to tell the browser
not to render the code but display it as pure text?
Why don't you just use View Source or equivalent command?

E.g.

I want
<p>Hello World</p>
to be displayed in the browser.

I have tested <code><p>Hello world</p></code>, but that doesn't work.

Waht can I do? Thanks in advance
Martin


Jul 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.