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

2
  • 2
    What encoding is your output in? My guess is ISO-8859-1. Commented Nov 19, 2011 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 &#937 -> Omega-sign conversion. Thanks a lot! Commented Nov 19, 2011 at 12:07

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for clarifying that. Indeed, I saw two "strange" characters, but didn't know that was the reason.
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');
                                          ^^^^^

Comments

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

1 Comment

phpwact.org contains really useful information, thanks! What a great community is Stackoverflow..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.