使用PHP将证书从文件提取到字符串

时间:2016-03-28 13:35:12

标签: php

我是PHP的新手,我有这样的证书文件:

cert.pem 文件内容:

-----BEGIN CERTIFICATE-----
MIID3zCCAsegAwIBAgIJAKeRq8Dl6HE3MA0GCSqGSIb3DQEBCwUAMIGFMQswCQYD
VQQGEwJFRTETMBEGA1UECAwKU29tZS1TdGF0ZTEOMAwGA1UEBwwFVGFydHUxDjAM
BgNVBAoMBUhJVFNBMQ4wDAYDVQQLDAVFRU5ldDETMBEGA1UEAwwKc2VydmVyLmNv
bTEcMBoGCSqGSIb3DQEJARYNc3ZodUBlZW5ldC5lZTAeFw0xNjAzMjgxMjQ2NDBa
Fw0xNjA0MjcxMjQ2NDBaMIGFMQswCQYDVQQGEwJFRTETMBEGA1UECAwKU29tZS1T
dGF0ZTEOMAwGA1UEBwwFVGFydHUxDjAMBgNVBAoMBUhJVFNBMQ4wDAYDVQQLDAVF
RU5ldDETMBEGA1UEAwwKc2VydmVyLmNvbTEcMBoGCSqGSIb3DQEJARYNc3ZodUBl
ZW5ldC5lZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALAzpCCn9aID
ByqSzI5BaDVznFnMAll0OGKbdiqNWI0ClvOMc+faRP1Bnd39WiMvVXZ5Yew04iwm
OjSj2uzM+1hZfnxdZLKD/gJZZIoZP8Yrc5urqI87GFPEsrqBfmKr8vC9Pvt5WPcV
F4LObLiSSo8QT98o6llxIVYqPpMQOL2LRDL4FvJ/wQFVg4SRtZPPLmI6z1Tp3QwR
D7//D3eJKeJsP4ZTJllmTxGMnW+05WIEF6HP7kjwoWUe/LXly221ecWbAy6vZHVF
n6WZPh8D14mXJuzbr1K+isG9P5au3A2dZWYgvdW5V6GbeFMLgR+o0WzEUbUI77eo
U2ZhQZB2zFsCAwEAAaNQME4wHQYDVR0OBBYEFBJ5ATknaTeHbRX3YsZwbJbqoefG
MB8GA1UdIwQYMBaAFBJ5ATknaTeHbRX3YsZwbJbqoefGMAwGA1UdEwQFMAMBAf8w
DQYJKoZIhvcNAQELBQADggEBABUFAm72zOs0sKZF8b4gwbH1Jrru6922dyblxIAb
/GyZMgTejqLl9f1UKx25Zja8RCbyQF155a24I0pxupWW5LJNTUWKaOtkQqfXMcF4
pm6suVLZRanAcAJrt9nUWdzYortQKYNjWXLSj4ffz7wNvBcWLaJTsp0AgF9+tOBD
8jZNoeg05QRTDLvNRVyH41JTxQ0q0Fd8mryX4OSS7FtyJ8wHW+befJ7gf0UprjVC
7WqBHiCab5viv6QQqr6HnbQNvXex+q4nOV1dSH9vaun7ozsgSzXgKHohkz1K15wT
L2S3kChZ+Un47xRTxeaGudmO4kueX4q3DTYN2+nWRpPkHwI=
-----END CERTIFICATE-----

我想将-----BEGIN CERTIFICATE----------END CERTIFICATE-----之间的所有行合并为一行而不换行。像这样:

  

$证书=“MIID3zCCAsegAwIBAgIJAKeRq8Dl6HE3MA0GCSqGSIb3DQEBCwUAMIGFMQswCQYDVQQGEwJFRTETMBEGA1UECAwKU29tZS1TdGF0ZTEOMAwGA1UEBwwFVGFydHUxDjAMBgNVBAoMBUhJVFNBMQ4wDAYDVQQLDAVFRU5ldDETMBEGA1UEAwwKc2VydmVyLmNvbTEcMBoGCSqGSIb3DQEJARYNc3ZodUBlZW5ldC5lZTAeFw0xNjAzMjgxMjQ2NDBaFw0xNjA0MjcxMjQ2NDBaMIGFMQswCQYDVQQGEwJFRTETMBEGA1UECAwKU29tZS1TdGF0ZTEOMAwGA1UEBwwFVGFydHUxDjAMBgNVBAoMBUhJVFNBMQ4wDAYDVQQLDAVFRU5ldDETMBEGA1UEAwwKc2VydmVyLmNvbTEcMBoGCSqGSIb3DQEJARYNc3ZodUBlZW5ldC5lZTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALAzpCCn9aIDByqSzI5BaDVznFnMAll0OGKbdiqNWI0ClvOMc + faRP1Bnd39WiMvVXZ5Yew04iwmOjSj2uzM + 1hZfnxdZLKD / gJZZIoZP8Yrc5urqI87GF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