我有这样的东西
<a href='mailto:mike@example.com?subject=<?php print rawurlencode('This is the subject.');?>&body=<?php print rawurlencode('Line 1 of body. Line 2 of body.');?>'>Email</a>
我想在消息正文中加入一个换行符。我发现通过谷歌,你可以把%0D%0A到mailto做一个换行,但问题是,rawurlencode将编码它。我可以在rawurlencode中输入什么来使换行符显示在消息中
如果你使用双引号,你可以在字符串中添加'r'n
字符,这将避免你所描述的双重编码问题。
<?php
echo rawurlencode("Line One.'r'nLine Two.");
/* Line%20One.%0D%0ALine%20Two. */
http_build_query函数可能也很方便。
<?php
$params = array(
'subject' => 'Subject',
'body' => "Line One.'r'nLine Two."
);
echo http_build_query($params);
/* subject=Subject&body=Line+One.%0D%0ALine+Two. */
'n
-这叫做换行-特殊字符