代码java转换为php

I have a java code that want converted to php .

public String getSHA1Hash(String input) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        String SHA1Hash = null;
        MessageDigest md = MessageDigest.getInstance("SHA1");
        md.reset();
        byte[] buffer = input.getBytes("UTF-8");
        md.update(buffer);
        byte[] digest = md.digest();
        String hexStr = "";
        for (int i = 0; i < digest.length; i++) {
            hexStr += Integer.toString((digest[i] & 0xff) + 0x100, 16).substring(1);
            SHA1Hash = hexStr;
        }
        return SHA1Hash;

help

PHP has a function sha1() that creates a sha1 hash from the input string. No need to convert the java function and rebuild the logic.

PHP has a native function to hash sha1 strings:

Example from Manual:

$str = 'apple';

if (sha1($str) === 'd0be2dc421be4fcd0172e5afceea3970e2f3d940') {
    echo "Would you like a green or red apple?";
}

This will give the same output as your Java code would give for "apple".