Print html code

4

How to print html code?

Example:

<div id="css"><link rel="stylesheet" href="jquery.css.css"></div>

It does not print the link tag, it links to another css, I want to write that tag pro user read ...

    
asked by anonymous 16.04.2014 / 01:48

3 answers

5

To do this you need to escape some special characters ** , for example:

" para &quot;   
' para &apos;   
& para &amp;    
< para &lt;
> para &gt;

To facilitate you can use the htmlentities function.

The code:

<div id="css"><link rel="stylesheet" href="jquery.css.css"></div>

Equivalent:

&lt;div id=&quot;css&quot;&gt;&lt;link rel=&quot;stylesheet&quot;href=&quot;jquery.css.css&quot;&gt;&lt;/div&gt;

** Others can be seen here .

    
16.04.2014 / 02:52
5

Use &lt; instead of < , and &gt; instead of > .

    
16.04.2014 / 01:57
1

You can print special characters in HTML using HTML Entities .

If you want you can use this here converter.

Server languages - such as PHP, Ruby, Python - have their own functions to convert a string to another with encoded characters.

When you go to print any text that was entered by the user (such as a post from a blog, for example) it is recommended to use this function to avoid JavaScript injection attacks . In this type of attack someone with malicious intent can write script tags that will run on the user's machine without their consent.

    
16.04.2014 / 03:02