encoding URL parameter in Ruby, and correctly decoding it with php

addex03 picture addex03 · Mar 8, 2012 · Viewed 9.8k times · Source

I want to encode an URL parameter with Ruby. The URL parameter not encoded is like this:

index.php?hash=tlNmgzWNFelvIH1o9ZAWFifpB3RwZOh6DCt5OdIfJCWLo9iZSRONWk1D1rEnSxUp|hi8JcsAHkznPkDFfaS1+xw==

Then I want to decode it from PHP!

I tried ruby:

ERB::Util::url_encode(param)

And then in Php urldecode($param); does not seem to work!

Answer

pdu picture pdu · Mar 8, 2012

Use CGI::escape on rubyside.

http://ruby-doc.org/stdlib-1.9.3/libdoc/cgi/rdoc/CGI.html#method-c-escape

url_encoded_string = CGI::escape("'Stop!' said Fred")
   # => "%27Stop%21%27+said+Fred"