urlencode
-
In Ruby, we use the
CGIclass to encode 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
urlencodefunction, we’ll use theCGI.escapeclass method.PHP
$result = urlencode("Hello <b>there!</b>"); var_export($result); // => 'Hello+%3Cb%3Ethere%21%3C%2Fb%3E'
Ruby
require 'cgi' p CGI.escape("Hello <b>there!</b>") # => "Hello+%3Cb%3Ethere%21%3C%2Fb%3E"
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.

