Friday, November 12, 2010

Convert all HTML entities to their applicable characters in PHP

To convert  HTML entities to their applicable characters in PHP you can use the html_entity_decode function. It is easy to use function this is how it works
For example if you want to decode a variable

<?php
$orig 
"I'll \"walk\" the <b>dog</b> now";
$a htmlentities($orig); // To convert encode the string
$b html_entity_decode($a); // To convert back

echo 
$a// I'll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; now
echo $b// I'll "walk" the <b>dog</b> now
?>

No comments:

Post a Comment