urldecode
-
In Ruby, we use the
CGIclass to decode a URL. We first need to require theCGIlibrary usingrequire "cgi". This is similar to usingrequire_onceto include a class in PHP.To get the equivalent result of PHP’s
urldecodefunction, we’ll use theCGI.unescapeclass method.PHP
$result = urldecode('Hello+%3Cb%3Ethere%21%3C%2Fb%3E'); var_export($result); // => 'Hello <b>there!</b>'
Ruby
require 'cgi' p CGI.unescape("Hello+%3Cb%3Ethere%21%3C%2Fb%3E") # => "Hello <b>there!</b>"
see also
Looking for Rails or PHP web application development, integration, and training?
Rails for PHP is brought to you by Maintainable Software. Get custom web applications and personalized training from the authors of the book and website.

