- str_replace: documentation ( source)
- trim: documentation ( source)
- wordwrap: documentation ( source)
<?php
$start_key = <<< TEXT
-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEAp11fZi2kaPCCdOYQPHkHItqGcXaF0Uu9qfBBrcaDXo/Vaqy/niZt
34mO+l+7t/LQjsZl4P/Vjr4wQHZ2rd7PS1rL4XC08vn40szoCpfwyQcnirLkSzx0
wEu8a+bTCNP0i/XLoAaPsWKyZuF9oT6pmPtvvlHxqunaTrqNtFIQNWXrPksZEXh+
zx/2Z5dQ88QIWH6uRMbT+oq9IBE9VGBawzFPwpER2b4sX1ig+vgZhMhSGmHY0/qO
VmW7m09T5UnnqSdG1nyICIJ17HBXaDToeqRrwiq7SamkBYpu4KP7ZGFo41/MHsnD
NQ7kr7xwDQr+H8FmnSO1f9nB33WvboHJcwIDAQAB
-----END RSA PUBLIC KEY-----
TEXT;
$start_key = str_replace('-----BEGIN RSA PUBLIC KEY-----', '', $start_key);
$start_key = trim(str_replace('-----END RSA PUBLIC KEY-----', '', $start_key));
$key = 'MIICIjANBgkqhkiG9w0BAQEFAAOCAg8A' . str_replace("\n", '', $start_key);
$key = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($key, 64, "\n", true) . "\n-----END PUBLIC KEY-----";
echo openssl_pkey_get_public($key);