htmlspecialchars_decode() function will converts some predefined HTML entities back to characters. Here is the list of predefined characters. The converted entities are: & & (ampersand), " ” (double quote), (when ENT_NOQUOTES is not set), ' (when ENT_QUOTES is set), < and >.
It is opposite of htmlspecialchars() function.
[table caption=”List of available flags constants are” max-width=”100%” colwidth=”25%|75%” colalign=”left|left”]
Constant Name, Description
ENT_COMPAT, It will convert double-quotes only.
ENT_QUOTES, It will convert both double and single quotes.
ENT_NOQUOTES, It will not convert both double and single quotes.
ENT_HTML401, Handle code as HTML 4.01.
ENT_XML1, Handle code as XML 1.
ENT_XHTML, Handle code as XHTML.
ENT_HTML5, Handle code as HTML 5.
[/table]
This will return a decoded string.
[table caption=”” width=”100%” colwidth=”25%|75%” colalign=”left|left”]
Version, Description
PHP 5.4.0 , The constants ENT_HTML401 / ENT_XML1 / ENT_XHTML and ENT_HTML5 were added.
[/table]
<?php $strExample = '<a href="http://www.tutorialmines.net">Click to go tutorialmines</a><br />'; echo htmlspecialchars_decode($strExample); echo "<br />"; $strExample1 = '<b><i>www.tutorialmines.net. I am bold and italic.</i></b>'; echo htmlspecialchars_decode($strExample1); ?>
In above example ,We have a string ‘<a href=”http://www.tutorialmines.net”>Click to go tutorialmines</a>’; and string ‘<b><i>www.tutorialmines.net. I am bold and italic.</i></b>’;. Now see how the functions htmlspecialchars_decode() will convert them in the HTML view source of the page .
See below is the HTML output of above code view source of browser.
<!DOCTYPE html> <html> <body> <a href="http://www.tutorialmines.net">Click to go tutorialmines</a><br /><br /><b><i>www.tutorialmines.net. I am bold and italic.</i></b> </body> </html>
See below is the output of above code in web browser.
www.tutorialmines.net. I am bold and italic.
This example will show the use of different flags constants in htmlspecialchars_decode() function. We are taking single and double quotes in this example and see how this function behaves when constant flags are used –
<?php $str = ""He said, 'You can learn PHP here' ""; echo htmlspecialchars_decode($str, ENT_COMPAT); // This will only convert double quotes echo "<br/>"; echo htmlspecialchars_decode($str, ENT_QUOTES); // This will converts double and single quotes echo "<br/>"; echo htmlspecialchars_decode($str, ENT_NOQUOTES); // This will not convert any quotes ?>
See below is the HTML output of above code i.e. View Source in Web browser.
<!DOCTYPE html> <html> <body> "He said, 'You can learn PHP here' "<br/> "He said, 'You can learn PHP here' "<br/> "He said, 'You can learn PHP here' " </body> </html>
See below is the output of above code in Web browser.
Convert some characters to HTML entities using the Western European character-set :
<?php $str = "Bonjour chers visiteurs ! <br /> N'hésitez pas à nous contacter pour tous vos projets ou questions concernant - <br /> Développement web <br /> Web Designing <br /> Services de référencement <br /> Google Classement de la page <br /> Développement d'applications Android."; echo htmlspecialchars_decode($str, ENT_QUOTES); // Will only convert double quotes (not single quotes), and uses the character-set Western European ?>
See below is the HTML output of above code i.e. View Source in Web browser.
<!DOCTYPE html> <html> <body> Bonjour chers visiteurs ! <br /> N'hésitez pas à nous contacter pour tous vos projets ou questions concernant - <br /> Développement web <br /> Web Designing <br /> Services de référencement <br /> Google Classement de la page <br /> Développement d'applications Android. </body> </html
See below is the output of above code in Web browser.
When it comes to children, there’s one universal truth: the right toy can spark imagination, build skills, and make memories…
In today’s digital age, where screens and gadgets dominate our children’s lives, there’s something heartwarming about a well-loved plush toy…
In a world dominated by screens and fast-paced routines, it’s easy to forget the simple magic of a toy in…
In the heart of Delhi’s vibrant streets lies a world where imagination meets innovation — the magical universe of toys.…
When was the last time a toy truly amazed you—not just as a product, but as a thoughtful tool for…
In the digital age, the way we experience childhood has changed, but the essence remains the same—imagination, exploration, and joy.…