如何使PHP输出像这样:

时间:2015-08-31 09:32:25

标签: php

原文:

-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCa3Zrd4NkjglMUr3tCa7gLaru2
9Usz5Vpr+k42ADAKrcFjxS/iKgwdBVXhwziWkDaePnDXgmlg5IrxZvJHoyOmIyku
Z1e6guSGGAEPdEEGojOuW9vXe1z1x+HK1u0q328NO4Aezx8QFOmofzSGw+q3svjr
hEiCqWLAcMuOPLK1RwIDAQAB
-----END PUBLIC KEY-----

我想这样做:

-----BEGIN PUBLIC KEY-----\
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCa3Zrd4NkjglMUr3tCa7gLaru2\
9Usz5Vpr+k42ADAKrcFjxS/iKgwdBVXhwziWkDaePnDXgmlg5IrxZvJHoyOmIyku\
Z1e6guSGGAEPdEEGojOuW9vXe1z1x+HK1u0q328NO4Aezx8QFOmofzSGw+q3svjr\
hEiCqWLAcMuOPLK1RwIDAQAB\
-----END PUBLIC KEY-----

我尝试使用

$publickey=str_replace("\n", "\\\n", $publickey);

但输出是这样的:

-----BEGIN PUBLIC KEY-----
\
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDOyHkuH6cs4+c2p+7+IbCBCagp
\
jRd5TYpFa2Qxk/kGCNOwaA0CpCOYvTcK0VbpsQ0ajt9yvN4NraX2Spb9fT5atzi1
\
NRqj9uOPSGKD2pTpwzGsytT5TAsBFapMzQn6lJHALOAr4l4jsqkwCO4GgaQiuiIw
\
0KnDqrWB3QUpssHeoQIDAQAB
\
-----END PUBLIC KEY-----

有谁能告诉我为什么输出是这样的?我用“回声”表示赞。

1 个答案:

答案 0 :(得分:0)

哦,我找到了答案。使用Windows操作系统时有一个“\ r”。问题解决了。