jperelli
jperelli

Reputation: 7197

How should I use htmlentities to display utf ó (not ó)

I'm writing a small newsletter in PHP

I'm using PHP's htmlentities($str) so I'll have no problems with encoding in client's email.

This $str is coming out of mysql.

I see ó when it's supposed to be a ó in the client.

I'm also writing some text in the newsletter where I echo "ó"; and I see it in the client as ó.

Then I suppose that I have to make some treatment to $str before appliyng the htmlentities but I don't understand what should I do.

How can I know what is wrong with (what treatment should I do to) $str?

Upvotes: 1

Views: 4603

Answers (1)

jperelli
jperelli

Reputation: 7197

This solves the issue

https://stackoverflow.com/a/10539209/912450

//You must manually specify the encoding (UTF-8) for htmlentities()
echo htmlentities($str, null, "UTF-8");

The problem seems to be (according to documentation) that if UTF-8 is not specified, in PHP versions prior to 5.4.0, ISO-8859-1 is the default encoding for htmlentities.

If $str is UTF8 encoded then it will only work ok in PHP>=5.4.0, where UTF-8 is the default encoding for htmlentities if no encoding is specified.

Upvotes: 4

Related Questions