Does php urlencode do the same with java urlencode?

In PHP:

php -r "echo urlencode('["IM"]'); "  

Result %5BIM%5D

But in java

String text = URLEncoder.encode('["IM"]',"UTF-8");
System.out.println("text" + text);

Result text%5B%22IM%22%5D

What is the difference between these two functions? How can I implement Java code to execute the same php function?

+3
source share
3 answers
php -r "echo urlencode('["IM"]'); "

The result is% 5BIM% 5D, because the urlencode function actually only accepts a string [IM]as its input. and in java

String text = URLEncoder.encode('["IM"]',"UTF-8");

Actually passed string: ["IM"]that generates a value %22that is an encoded string for the "quotation mark.

+1
source
String text = URLEncoder.encode('[IM]',"UTF-8");
System.out.println("text" + text);

gives %5BIM%5D

echo urlencode('["IM"]');

gives %5B%22IM%22%5D

echo urlencode('[IM]');

gives %5BIM%5D

echo urlencode('[\"IM\"]');

gives %5B%5C%22IM%5C%22%5D

+3
source

try to avoid internal qoutes

php -r "echo urlencode('[\"IM\"]'); "
+1
source

All Articles