Jun
6
2011
6
2011
PHP Urlencode equivalent in Ruby
If you are finding a way to encode urls in ruby then here is a quick tip -
Short Answer: You could use the URI class or the CGI class.
We have CGI.escape and URI.escape, but they have some slight differences. I have tried to show the differences in IRB as follows -
$ irb irb(main):001:0> str = 'hello world' => "hello world" irb(main):002:0> require 'uri' => true irb(main):003:0> URI.escape(str) => "hello%20world" irb(main):004:0> require 'cgi' => true irb(main):005:0> CGI.escape(str) => "hello+world" irb(main):006:0> url = 'http://example.com/åäö' => "http://example.com/åäö" irb(main):007:0> URI.escape(url) => "http://example.com/%C3%A5%C3%A4%C3%B6" irb(main):008:0> CGI.escape(url) => "http%3A%2F%2Fexample.com%2F%C3%A5%C3%A4%C3%B6"
So i hope you can see the difference now and can choose the one you need.
Cheers!
Popularity: 2% [?]
Related Posts
Leave a comment
Subscribe
Recent Posts
- Login into phpmyadmin without username and password
- 10+ tips to localise your php application
- 40+ Techniques to enhance your php code – Part 3
- 40+ Techniques to enhance your php code – Part 2
- 40+ Techniques to enhance your php code – Part 1
- CSSDeck – Collection of Pure CSS Creations
- Execute shell commands in PHP
- Php get list of locales installed on system
- Sound cracking in Ubuntu 11.10
- PHP script to perform IP whois
Binarytides
Tags
amazing php techniques
amazing php tips
apache
box2d
bsnl
c
c++ portscanner code
cron
css
dns
enhance php code
hacking
html
html5
improve php code
javascript
linux
master php code
masters php techniques
mysql
networking
optimize php code
packet sniffer c
php
php advanced techniques
php best practices
php techniques
php tips
php tips and tricks
php tutorial
portscanner code c
python
raw socket programming
raw socket programming c
raw socket programming tutorial
ruby
security
socket programming
socket programming tutorial
Sockets
ubuntu
useful php techniques
winpcap
winsock
write efficient php code
An article by f00




