Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does php urlencode the same with java urlencode?

In PHP:

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

The result is %5BIM%5D

But in java

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

The result is text%5B%22IM%22%5D

What's the different between these two functions? How can I implement a java code to complete the same function of php?

like image 355
littletiger Avatar asked Sep 05 '26 07:09

littletiger


1 Answers

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

like image 80
Jack Avatar answered Sep 07 '26 21:09

Jack



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!