1

In my project I currently use htmlentities() to filter data coming from the database:

echo htmlentities($variable_name);

I am in the USA and this works fine for me. My friend is in Brazil and for him some text characters don't show up correctly.

How can I use htmlentities() so it internationalizes properly?

1
  • What Keoki said. Also since you are generally using it a lot it's highly advisable to write a wrapper function -- html() and h() are common. Using htmlspecialchars() would eschew the charset issue and be compliant to the older xhtml syntax. (But better use the charset parameter for reliability). Commented Jun 25, 2011 at 4:28

3 Answers 3

5

The problem could be that the output is not encoded in UTF-8. According to the php docs for htmlentities, the function

takes an optional third argument charset which defines character set used in conversion. Presently, the ISO-8859-1 character set is used as the default.

So you can try calling

htmlentities($string, ENT_COMPAT, 'UTF-8');

instead, and that might fix the problem, since it's not the default character encoding.

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

1 Comment

@usnidorg could you please also try simply adding <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> in the head, and not pass additional parameters to htmlentities and check if that works
0

While I suspect Keoki has it correct, another possible problem could be the font. If using a special character where your friend's font doesn't contain that character, they'll just see the missing character sign. In the webpage or whatever medium you are using to post the character, be sure that a font is set, as there's no guarentees on the default font working.

If neither of these be the case though, what is an example character that isn't showing up? Can you post the full code you are using?

Comments

0

You can also try iconv to Convert string to requested character encoding

http://www.php.net/manual/en/function.iconv.php

Comments

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.