How to convert special HTML entities back to characters in PHP
Topic: PHP / MySQLPrev|Next
Answer: Use the PHP htmlspecialchars_decode()
function
You can use the PHP htmlspecialchars_decode()
function to convert the special HTML entities such as &
, <
, >
etc. back to the normal characters (i.e. &
, <
, >
).
The htmlspecialchars_decode()
function is opposite of the htmlspecialchars()
function which converts special HTML characters into HTML entities. Let's check out an example:
Example
Download<?php
$my_str = "I'll come & <b>"get you"</b>.";
// Decode &, <, > and "
echo htmlspecialchars_decode($my_str);
// Decode &, <, >, " and '
echo htmlspecialchars_decode($my_str, ENT_QUOTES);
// Decode &, < and >
echo htmlspecialchars_decode($my_str, ENT_NOQUOTES);
?>
Related FAQ
Here are some more FAQ related to this topic: