0

I actually have a fairly simple question but I'm unable to find an answer anywhere. The PHP function html_entity_decode is supposed to "converts all HTML entities to their applicable characters from string."

So, since Ω is the HTML encoding for the Greek captical letter Omega, I'd expect that echo html_entity_decode('Ω', ENT_COMPAT, 'UTF-8'); would output Ω. But instaid, it outputs some strange characters which my browser can't recongize. Why is this?

Thanks,

Martijn

Martijn
  • 5,491
  • 4
  • 33
  • 41
  • 2
    What encoding is your output in? My guess is ISO-8859-1. – Pekka Nov 19 '11 at 11:57
  • Hm, you're right. Now I've added `header('Content-type: text/html; charset=utf-8');` to my file and I'm able to see the Omega sign. So stupid I didn't think about that before. A second problem I was dealing with, was that the source contained &#937, so I had to run html_entity_decode twice: once for the &amp -> & conversion, second for the Ω -> Omega-sign conversion. Thanks a lot! – Martijn Nov 19 '11 at 12:07

3 Answers3

2

When you convert entities into UTF-8 characters like your last parameter specifies, your output encoding must be UTF-8 as well. Otherwise, in a single-byte encoding like ISO-8859-1, you will see double-byte characters as two broken single ones.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • Thanks for clarifying that. Indeed, I saw two "strange" characters, but didn't know that was the reason. – Martijn Nov 19 '11 at 12:31
1

It's works fine:

http://codepad.viper-7.com/tb2LaW

Make sure your webpage encoding is UTF-8

If you have different encoding on webpage change this:

html_entity_decode('Ω', ENT_COMPAT, 'UTF-8');
                                          ^^^^^
Peter
  • 16,453
  • 8
  • 51
  • 77
0
header('Content-type: text/html;charset=utf-8');

mysql_set_charset("utf8", $conn);

Refer this URL:-

http://www.phpwact.org/php/i18n/charsets

php mysql character set: storing html of international content

Community
  • 1
  • 1
Siva Charan
  • 17,940
  • 9
  • 60
  • 95
  • phpwact.org contains really useful information, thanks! What a great community is Stackoverflow.. – Martijn Nov 19 '11 at 12:34