PHP html_entity_decode()
Anonymous contributor
Published Nov 12, 2023
‘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:
dogdog
Codebyte Example
This example converts double and single quotes:
All contributors
- Anonymous contributor
Learn PHP on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours