HTML question...
- MrMojoRisin5
-
MrMojoRisin5
- Member since: Jun. 21, 2011
- Offline.
-
- Forum Stats
- Member
- Level 12
- Programmer
I want to use some HTML script as plain text, but even though I have tried putting it in header, paragraph or script tags, it is still seen by the browser as actual HTML script and it won't display. Does anybody know how to solve this?
- deckheadtottie
-
deckheadtottie
- Member since: Oct. 21, 2003
- Offline.
-
- Forum Stats
- Supporter
- Level 59
- Programmer
At 3/3/13 09:03 AM, MrMojoRisin5 wrote: I want to use some HTML script as plain text, but even though I have tried putting it in header, paragraph or script tags, it is still seen by the browser as actual HTML script and it won't display. Does anybody know how to solve this?
I don't really know what you mean. Do you want to display HTML elements in the document without them being parsed by the browser? Like the code tags below allow:
<p>These HTML elements aren't being displayed as they should as they're in code tags</p>
<em>this won't be in italics</em>
Post some code and an example of what you want to achieve. :)
- Diki
-
Diki
- Member since: Jan. 31, 2004
- Online!
-
- Forum Stats
- Moderator
- Level 13
- Programmer
In order to do that you need to replace the <> brackets, and ampersand, with their HTML character codes. The code for < is <, the code for > is >, and the code for an ampersand is &. You can do a simple find/replace to insert the codes in place of the literals.
I'm going to assume your server is running on Apache and you're to some extent using PHP in which case all you have to do is use the htmlspecialchars() function:
$html = "<p>This is some text <em>with html</em> in it.</p>
$safe = htmlspecialchars($html);
echo $safe; - smulse
-
smulse
- Member since: Mar. 24, 2005
- Offline.
-
- Forum Stats
- Member
- Level 31
- Blank Slate


