Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What are the differences between htmlentities and htmlspecialchars in PHP

Shulou Source: shulou.com Published: 2022-05-31 13:14:35 11月16日 Update

In this article Xiaobian for you to introduce in detail "what are the differences between htmlentities and htmlspecialchars in PHP", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "what are the differences between htmlentities and htmlspecialchars in PHP" can help you solve your doubts.

Both htmlentities and htmlspecialchars are used to convert special characters of a string into HTML character entities. There are only five special character sets escaped by htmlspecialcharsl.

'&' (ampersand) = >'&'

'' (double quote) = > 'when ENT_NOQUOTES is not set.

'' (single quote) = >'& # 039 'only when ENT_QUOTES is set.

''

The special character set escaped by htmlentities is the complete set of HTML character entities.

These two functions are explained in English in the php manual, and there is an English paragraph in the description of the htmlentities function:

This function is identical (identical) to htmlspecialchars () in all ways, except with htmlentities (), all characters which have HTML character entity equivalents (HTML)

Character entity equivalents is translated into HTML character entity equivalent) are translated into these entities.

From this sentence, we can also see that although the basic functions of the two functions are similar, there are still slight differences in them. Take a closer look at a passage in the htmlspecialchars function:

Certain characters (actually'&', double quotation marks (escaped only if ENT_NOQUOTES is not set), single quotation marks (escaped only if and only if ENT_QUOTES is set),') have special significance in HTML, and should be represented by HTML entities if they are to preserve their meanings. This function

Returns a string with some of these conversions made; the translations made are those most useful for everyday web programming. If you require all HTML character entities to be translated, use htmlentities () instead.

Note: the encoding format is finally specified when using these two functions.

After reading this, the article "what is the difference between htmlentities and htmlspecialchars in PHP" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it to understand it. If you want to know more about related articles, welcome to follow the industry information channel.

Tags: Character function escape special two entity article content character set quotation marks English proper same subtle almost functional but only string is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Information NVidia MySQL Microsoft