html_entity_decode()

Anonymous contributor's avatar
Anonymous contributor
Anonymous contributor's avatar
Anonymous contributor
Published Nov 12, 2023
Contribute to Docs

‘html_entity_decode()’ is the opposite of ‘htmlentities()’ in that it converts HTML entities in the string to their corresponding characters.

Syntax

html_entity_decode(str, flags, character-set)
  • string: - Specifies the string to decode
  • flags: - Specifies how to handle quotes and which document type to use.
  • character-set: These are optional strings that specify which character-set to use.

Example

The below example takes value for $orig and assigns it to $a using htmlentities(). Then it decodes it using html_entity_decode() and assigns it to $b. It then shows values for both $a and $b:

<?php
$orig = "dog";
$a = htmlentities($orig);
$b = html_entity_decode($a);
echo $a;
echo "\n";
echo $b;
?>

Output

The above example generates the following output:

dog
dog

Codebyte Example

This example converts double and single quotes:

Code
Output
Loading...

All contributors

Looking to contribute?

Learn PHP on Codecademy