Example: “Apple Junhua”.
At first, php urlencode was used, then java urldecode, and the word “Ping” was garbled.
After that, use PHP base64_encode, and then use java decode (using org.Apache.commons.codec.binary.base64 package). the word “ping” is OK, but the word “junhua” is misspelled.
Search said java uses nonstandard base64 decoding, so … to break.
The reason for the confusion is that your codes are inconsistent.
The encoding of urlencode in php is consistent with the system encoding (for example, windows default GB 2312 and Ubuntu default utf-8)
Therefore, you need to determine your system code first, and then pass this code in when calling java’s decode method according to the obtained system code (considering the traditional Chinese characters in your example, it is recommended that you use utf-8 encoding). the following is an example of my use of utf-8 encoding (under ubuntun in php environment)
<? Php Echo urlencode ("Apple Junhua"); ? >
Output: percentage E8 percentage 98 percentage 8B percentage E6 percentage 9E percentage 9C percentage E5 percentage 90 percentage 9B percentage E5 percentage 8D percentage 8E
String ret = java.net.url decoder.decode ("percentage E8 percentage 98 percentage 8B percentage E6 percentage 9E percentage 9C percentage E5 percentage 90 percentage 9B percentage E5 percentage 8D percentage 8E", "utf-8"); System.out.println(ret);
Output: apple junhua