Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Decoding Html Entities

I want to decode html entities using php html_entity_decode() but my html entities seem incompatible with the function.

Example Input String: html_entity_decode('<strong>');
Outputs: <strong>

Removing the 'amp;' solves the problem and produces <strong> but my file has 'amp;' before every html entity. A mass removal of amp; would probably solve the problem, but also very destructive to the html. Is it possible to convert my entities with this situation of an extra amp; before all entities?

like image 462
JMC Avatar asked Jul 20 '12 14:07

JMC


1 Answers

It's double encoded - Run the string through html_entity_decode() twice.

echo html_entity_decode( html_entity_decode('&amp;lt;strong&amp;gt;'));

This will output:

<strong>
like image 180
nickb Avatar answered Oct 11 '22 19:10

nickb