时间:2021-07-01 10:21:17 帮助过:5人阅读
在php中,怎样把字符串转为UTF-8字节数组? JAVA中的实现方式是getBytes(“UTF-8”),要和这个等价。
unpack
参考连接:
http://php.com/manual/en/function.pack.php
http://php.com/manual/en/function.unpack.php
test.php
Test.java
import java.io.*;
public class Test{
public static void main(String args[]){
String Str1 = new String("在php中");
try{
byte[] bytes = Str1.getBytes("UTF-8");
StringBuilder sb = new StringBuilder();
for (byte b : bytes) {
sb.append(String.format("%d ", b & 0xff));
}
System.out.println(sb.toString());
}catch( UnsupportedEncodingException e){
System.out.println("Unsupported character set");
}
}
}