Why htmlspecialchars_decode in PHP does not have the charset parameter as in its counterpart?
Asked Answered
E

2

6

There is a charset parameter in htmlspecialchars but the decode version does not have it. In comparison to the similar htmlentities, the encode and decode functions both have the charset parameter. So I can't choose what charset I am decoding back to?

Evaporation answered 17/5, 2010 at 7:55 Comment(0)
K
8

htmlspecialchars() requires the charset parameter only when converting charsets who's special characters are not in the 'default' positions. Hence, charsets ISO-8859-1, ISO-8859-15, UTF-8, cp866, cp1251, cp1252, and KOI8-R do not require the charset parameter.

htmlspecialchars_decode() converts entities (& " ' < >) back to their character equivalent and therefore does not need to be passed a charset.

As htmlentities() converts 'all' characters to their equivalent entity, a charset can be passed in html_entity_decode() to ensure the entities are decoded to the relevant character in the charset.

Keramics answered 17/5, 2010 at 9:45 Comment(0)
F
6

Simply because it only converts & " ' < > and nothing else.

If you want to decode all entities, use html_entity_decode(), you can pass the charset as the third parameter to it.

Forensic answered 17/5, 2010 at 8:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.