Re-escape.htmlspecialchars() rebuilds the entity form.
Same flags.ENT_QUOTES on both sides keeps quotes consistent.
Strict match.=== confirms an exact round-trip.
Frequently Asked Questions
htmlspecialchars_decode() converts special HTML entities back to their characters. It reverses htmlspecialchars() and decodes only &, <, >, and quote entities—not the full symbol set that html_entity_decode() handles.
string htmlspecialchars_decode(string $string, int $flags = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401). Pass the encoded string and optional ENT_* flags. There is no encoding parameter—unlike htmlspecialchars() and html_entity_decode().
Match the flags used during encoding. ENT_QUOTES decodes both single and double quote entities. ENT_COMPAT decodes double quotes only. ENT_NOQUOTES leaves quote entities unchanged.
Only if you re-escape before output or use the decoded text outside HTML. Decoding <script> back to a real tag and echoing it raw enables XSS. Decode for processing; use htmlspecialchars() when rendering to the page.