31

I need to convert a string like this:

A &#039;quote&#039; is <b>bold</b>

into:

A 'quote' is <b>bold</b>

html_entity_decode() did not work.

abraham
  • 46,583
  • 10
  • 100
  • 152
tzmatt7447
  • 2,329
  • 9
  • 24
  • 31

2 Answers2

64

Make sure you use the right quote_style:

html_entity_decode('A &#039;quote&#039; is <b>bold</b>', ENT_QUOTES);

ENT_QUOTES Will convert both double and single quotes. (PHP Manual: html_entity_decode)

Robert Ros
  • 1,526
  • 11
  • 22
25
mb_convert_encoding($string, "UTF-8", "HTML-ENTITIES");

You can replace "UTF-8" with whatever encoding you need (though depending on the encoding you choose, certain characters may not be representable).

Artefacto
  • 96,375
  • 17
  • 202
  • 225