Generating Subresource Integrity Checksums with PHP

Generating Subresource Integrity Checksums with PHP

<?php
function checkSum($algo, $input) {
$hash = hash($algo, $input, true);
$hash_base64 = base64_encode($hash);
return $algo.'-$hash_base64';
}
?>

Example <script src="https://code.rifix.net/jquery/3.1.0/jquery.min.js" integrity="<?php echo checkSum('sha384','https://code.rifix.net/jquery/3.1.0/jquery.min.js'); ?>" crossorigin="anonymous"></script>