Why do I need to convert
Simpler, because sometimes we need to display the HTML tag in the browser page, but the direct output <script>alert (1) </script>, when browsing the page will be implemented as HTML tag language, the workaround is to HTML tags are converted into HTML entities and then written into code, such as we want to display <script> alert (1) </script>, then our code should write: <script> $nbspalert (1) </script>. Why is there a in the middle? Because the attentive friend may have found out, I have a space in the middle of <script> and alert, that is to say, is the entity name of the space.
Crossing might have said, since code <script> $nbspalert (1) </script> The <script> alert (1) </script> is displayed, so if you want to display
<script> $nbspalert (1) </script> What kind of code should I write? The reason is very simple, a paragraph of text, if the display in the page with the code is inconsistent, it must be included in the HTML keyword, such as the previous code contains the keyword &, if you want to display in the browser & (HTML keyword), You need to replace the,& entity with its corresponding entity in your code for & , so to display <script> $nbspalert (1) </script> , the code required is &lt;script&gt; $amp; Nbspalert (1) &lt;/script&gt;
The following symbol lists the HTML entities:
PHP HTML Series functions
Look at the above, you may feel, wow, that every time to change, the eyes are looking at the flowers, there is nothing simple and error-prone method. The answer is yes, humans are so lazy, anything can be done in a convenient way.
The functions of the PHP HTML series are
The above four functions are prefixed with HTML, so I think I know the HTML tag. where Html_entity_decode () and Htmlspecialchars_decode () are converting HTML entities to HTML tags, htmlspecialchars () and htmlentities () are converting HTML tags is an HTML entity.
What are HTML tags, HTML entities