user460847
user460847

Reputation: 1618

PHP: utf-8 encode, htmlentities giving weird results

I'm trying to get data from a POST form. When the user inputs "habláis", it shows up in view source as just "habláis". I want to convert this to "habláis" for purposes of string comparison, but both utf8_encode() and htmlentities() are outputting habláis, and htmlspecialchars() does nothing. I would use str_replace but it won't recognize the á when it searches the string.

I'm using a charset of utf-8 consistently across pages. Any idea what's going on?

Upvotes: 3

Views: 849

Answers (2)

user456814
user456814

Reputation:

I'm not sure if this is your problem, but are you calling htmlentities with the UTF-8 parameter? I ask because that's not its default:

Like htmlspecialchars(), it 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 might want to try calling your function like this:

$output = htmlentities($input, ENT_COMPAT, 'UTF-8');

Does this solve your problem?

Upvotes: 3

Pekka
Pekka

Reputation: 449395

You are probably not specifying UTF-8 as the character set for the htmlentities() operation.

Upvotes: 4

Related Questions