Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 210
addex03 Avatar asked Mar 08 '12 11:03

addex03


People also ask

How decode URL in PHP?

The urldecode() function is an inbuilt function in PHP which is used to decode url which is encoded by encoded() function. Parameters: This function accepts single parameter $input which holds the url to be decoded. Return Value: This function returns the decoded string on success.

How encode URL in PHP?

PHP | urlencode() Function. The urlencode() function is an inbuilt function in PHP which is used to encode the url. This function returns a string which consist all non-alphanumeric characters except -_. and replace by the percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs.

What is encoding and decoding PHP?

However, the question is, why is it used? Encoding and decoding URL strings are used to convert general URL strings and characters into an arrangement that can be conveyed over the internet. In this tutorial, you will learn about two ways in which URL string can be encoded and decoded in PHP.

What is %2F in URL?

URL encoding converts characters into a format that can be transmitted over the Internet. - w3Schools. So, "/" is actually a seperator, but "%2f" becomes an ordinary character that simply represents "/" character in element of your url.


1 Answers

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"
like image 165
pdu Avatar answered Oct 04 '22 00:10

pdu