html_entity_decode
Turns HTML entities back into characters.
Syntax
html_entity_decode(string $string, int $flags = ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, ?string $encoding = null): stringParameters
| Parameter | Type | Description |
|---|---|---|
| $string | string | A string with entities such as `&`. |
| $flags | int | Optional. Which quotes to convert. |
| $encoding | ?string | Optional. The encoding. |
Return value
stringA string with regular characters.
Examples
Entities into characters:
<?php
echo html_entity_decode('Tom & Jerry © 2025');Output:
Tom & Jerry © 2025Notes
The exact reverse of htmlspecialchars() is htmlspecialchars_decode(). Decoded text is unsafe to print on a page again.
See also
- htmlspecialchars — Replaces HTML special characters with safe entities.
- strip_tags — Removes HTML tags from a string.
Related recipes
In the tutorial
- Security — The basics of PHP site security — XSS and escaping, SQL injection, password hashing, CSRF tokens and validating input.