lord rah
lord rah

Reputation: 1

HTML: how to stop a html code in a string written in PHP from appearing as a Html Element on the Web Page

I am having problem in making html code in a string written PHP from appearing as an html element on the web page. What i really want is to make the html code to show as text on the page. Is there a way to preserve the html code in a string as string on the page?

Upvotes: 0

Views: 702

Answers (2)

user1074324
user1074324

Reputation:

If you are displaying Html submitted by an end user, take it a step further and use http://htmlpurifier.org/ or http://tidy.sourceforge.net/ to remove potential submitted malicious code. For example, prevent some one from entering javascript, or php code, etc. That could in turn be used to cause trouble.

Upvotes: 0

Mr. Llama
Mr. Llama

Reputation: 20889

Use htmlentities().

It changes things like < and > to &lt; and &gt;.
Visually, they're exactly the same to the user but it won't be parsed as HTML tags.

Upvotes: 4

Related Questions