Example code, assume mycert.pem is a certificate containing both private and public key.
$cert = file_get_contents("mycert.pem");
$public = openssl_get_publickey($cert);
$private = openssl_get_privatekey($cert);
$data = "I'm a lumberjack and I'm okay.";
echo "Data before: {$data}\n";
openssl_seal($data, $cipher, $e, array($public));
echo "Ciphertext: {$cipher}\n";
openssl_open($cipher, $open, $e[0], $private);
echo "Decrypted: {$open}\n";