Differences between htmlentities and htmlspecialchars functions in php
Source: Internet
Author: User
There are two functions in php: htmlentities and htmlspecialchars. both functions are explained in English in the php Manual. the description of the htmlentities function contains the following two functions in php: htmlentities and htmlspecialchars, the php Manual is explained in English. the description of the htmlentities function is as follows:
This function is identical to htmlspecialchars () in all ways, except t with htmlentities (), all characters which have HTML character entity equivalents are translated into these entities.
From this sentence, we can also see that although these two functions have similar basic functions, there are still slight differences in them. Let's take a closer look at a paragraph in the htmlspecialchars function:
The translations saved Med are:
'&' (Ampersand) becomes '&'
'"' (Double quote) becomes '" 'When ENT_NOQUOTES is not set.
"'(Single quote) becomes"' only when ENT_QUOTES is set.
'<' (Less than) becomes' <'
'>' (Greater than) becomes '>'
We can understand that htmlspecialchars only converts the preceding html code, while htmlentities converts all the html code, along with the unrecognized Chinese characters in it.
We can use a simple example for comparison:
$ Str = 'test page ';
Echo htmlentities ($ str );
$ Str = 'test page ';
Echo htmlspecialchars ($ str );
The difference between the two codes is obvious.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.