开发者

Ruby on Rails escape umlauts in url

I try to post some parameters containing umlauts to a url (PHP Script). So I've to escape the parameters. But Ruby returns me an unexpected string.

PHP:

urlencode("äöü")开发者_如何转开发;

output: %E4%F6%FC

and RoR:

URI.escape("äöü")

output: %C3%A4%C3%B6%C3%BC

or:

CGI.escape("äöü")

output: %C3%A4%C3%B6%C3%BC

I'm working on Rails 3.0.5 and Ruby 1.9.2 and my application is setup for UTF-8. Where is my fault or what should I do?

Thanx andi


Welcome to the wonderful world of String encodings. As you noted, Ruby is configured for UTF-8, whereas your installation of PHP looks like it's trying to encode using ISO 8859-1.

To solve this, you need to make sure both of your scripts are operating using the same encoding, or explicitly convert your URL paramaters from UTF-8 to ISO 8859-1.


Maybe you should use something like this:

CGI.escape("äöü")

If you got an error try to require 'cgi' before.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜