eozzy
eozzy

Reputation: 68680

Converting HTML entities to their applicable characters

$str = '<div style="text-align:center"><img src="http://image.gif" border="0">';

echo html_entity_decode($str,ENT_COMPAT, 'UTF-8');

Outputs the same:

<div style="text-align:center"><img src="http://image.gif" border="0">

I'm expecting:

<div style="text-align:center"><img src="http://image.gif" border="0"></div>

Upvotes: 0

Views: 78

Answers (2)

AbraCadaver
AbraCadaver

Reputation: 78994

This has been double encoded, so you need to decode twice as &amp; needs to decode to & in order to get &lt; etc...

echo html_entity_decode(html_entity_decode($str));

If you are doing the encoding then look at the $double_encode parameter for htmlspecialchars() and htmlentities().

If encoded multiple times then you could use:

while(($str = html_entity_decode($str)) != $str) {}
echo $str;

Upvotes: 2

matcartmill
matcartmill

Reputation: 1593

Try using "htmlspecialchars_decode()" instead of "html_entity_decode()"

htmlspecialchars_decode

Upvotes: 0

Related Questions