Ruby url_encode

Escapes/Encodes the string, replacing all unsafe characters with codes.

Function

url_encode ( str )

Alias Function

u ( s )

Parameters

str - String to be encoded.

Return value

Returns escaped/encoded version of str

Example

require 'erb'
include ERB::Util

url = url_encode("http://example.com/?a=ruby url encode")
puts url

Output

http%3A%2F%2Fexample.com%2F%3Fa%3Druby%20url%20encode

Github

See also: