请问这个java里的函数如何用php语言表达出来?

新手上路,请多包涵
public static String MD5(String text, String charset) {
    char[] DIGITS = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
    MessageDigest msgDigest = null;
    try {
        msgDigest = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException var6) {
        throw new IllegalStateException("System doesn't support MD5 algorithm.");
    }
    try {
        msgDigest.update(text.getBytes(charset));
    } catch (UnsupportedEncodingException var5) {
        throw new IllegalStateException("System doesn't support your  EncodingException.");
    }

    byte[] bytes = msgDigest.digest();
    int l = bytes.length;
    char[] out = new char[l << 1];
    int i = 0;

    for(int j = 0; i < l; ++i) {
        out[j++] = DIGITS[(240 & bytes[i]) >>> 4];
        out[j++] = DIGITS[15 & bytes[i]];
    }
    String md5Str = new String(out);
    return md5Str;
}

请问以上代码如何转为php的函数,新手看不太懂java\~ 谢谢各位了!

请问这个java里的函数如何用php语言表达出来?

阅读 974
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题