0

After spending the entire morning going through questions on Stack Overflow, I'm seeking help. I need to convert both, Unicode entities and HTML entities into UTF-8 text.

$string = "Let's "Kiss & Makeup"";
//-> Let's Kiss & Makeup "lalala"

I manage to decode the HTML entities alone (using html_entity_decode() and htmlspecialchars_decode). Not even this widely linked Polyfill does the trick. Since none of the functions I tried decoded Unicode entities, I haven't even tried figuring out how a combination of decoding functions.

idleberg
  • 12,634
  • 7
  • 43
  • 70

1 Answers1

0

The only issue is specifically with single quotes and the default ENT_COMPAT flag of html_entity_decode, which "leaves single-quotes alone". Simply set the ENT_QUOTES flag instead to convert all quotes:

echo html_entity_decode($string, ENT_QUOTES | ENT_HTML401, 'UTF-8');
deceze
  • 510,633
  • 85
  • 743
  • 889