3

I am sending HTML news letters and composing them run-time. I need to put HTML code as string in the HTML news letter. Since the HTML code I need to place as a string is also html it executes in the browser but I dont want this, I want to display that code itself. Any help will be appreciated.

1
  • 2
    why -1??? Who is this god on the planet earth who knows everything and votes -1 for humans who knows less than them......... Commented Apr 2, 2013 at 13:12

2 Answers 2

4

Wrap the HTML in <code> or <pre> tags

and make sure you use an HTML entity encoder on the code first so that it will display < and > properly.

Sign up to request clarification or add additional context in comments.

1 Comment

For added fun, if you can execute javascript, you can use something like SyntaxHighlighter (alexgorbatchev.com/SyntaxHighlighter) to make the code all purty-like.
1

You need to encode the < and > as well as other html special characters. Many languages have libraries that do this such as php's htmlspecialchars and ruby's h(), but it seems like you're just writing the HTML out.

<pre class="htmlcode">&lt;html&gt;</pre>

The above would display <html>.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.