Thursday, December 30, 2010

Calculate sha1 thumbprint of ssl certificate

<?php
function sha1_thumbprint_pem($pem_file_contents)
{
    $file $pem_file_contents;
    $file preg_replace('/\-+BEGIN CERTIFICATE\-+/','',$file);
    $file preg_replace('/\-+END CERTIFICATE\-+/','',$file);
    $file trim($file);
    $file str_replacearray("\n\r","\n","\r"), ''$file);
    $bin base64_decode($file);
    return sha1($bin);
}
?>

Tuesday, December 14, 2010

preg_replace/preg_match utf8

preg_replace('/([^a-z\x{00C0}-\x{02AF}\x{0380}-\x{FFFF}\.\, ]|[\.\,][\.\,]+)/iu', '', $str);//allows most utf8