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?
The result is %5BIM%5D because the function urlencode is actually only taking the string
[IM]as its input. while in javaThe string being passed is actually:
["IM"]which generates the value%22which is encode-string for"the quote mark.