Kris VW
Kris VW

Reputation: 51

Cakephp url parameter encoding problem?

In cakephp, I would like to use an url parameter which might contain some special chars like é or è.

When I print $this->params['url'] for this url for example: http://dev.family/registration?fname=kr%E9s

I get: Array ( [url] => registration [fname] => kr�s )

So the é becomes a question mark.

I tried urldecode, but I doesn't help. I guess this has something to do with UTF-8 encoding, but I don't know where to search.

Any suggestions?

Krikke

Upvotes: 2

Views: 1748

Answers (2)

Kris VW
Kris VW

Reputation: 51

I just fixed the problem thanks to B7ackAnge7z.

The htmlentities function worked, but translates krés to krés. This fixes the problem with the question mark.

But.. I want to use this value to pre-fill a form input. So the input would contain krés, which is not what I intented.

So I prefill it with this value now:

html_entity_decode(htmlentities($this->params['url']['fname']), ENT_COMPAT, 'UTF-8')

-> convert the value with htmlentities and then decode it again to UTF-8. Somewhat a dirty fix...

I guess cake doesn't decode URL parameters to UTF-8 default or maybe I should worry about an encoding problem somewhere in my cake project?

Thx!

Upvotes: 1

Victor
Victor

Reputation: 5769

Try htmlentities() function.

Upvotes: 1

Related Questions