<?php
$g = stream_context_create (array("ssl" => array("capture_peer_cert" => true)));
$r = fopen("https://www.google.com/", "rb", false, $g);
$cert = stream_context_get_params($r);
$certinfo = openssl_x509_parse($cert['options']['ssl']['peer_certificate']);
echo "Certificate info: <pre>". print_r($certinfo, true) ."</pre>";