PHP urlencode() 和空格
我有这个字符串要编码(带换行符)
发件人 ID
发件人 ID
发件人 ID
使用此 urlencode 生成器 时,我得到所需的输出,但是
Sender%20ID%0ASender%20ID%0ASender%20ID
当我使用 php urlencode 时() 我得到这个输出
Sender+ID%0D%0ASender+ID%0D%0ASender+ID
当使用 php rawurlencode() 我得到这个输出
Sender%20ID%0D%0ASender%20ID%0D%0ASender%20ID
如何实现与生成器相同的输出?我需要它相同,因为只有当换行符的 urlencode 为 %0A 时,黑莓手机才会正确显示换行符(我正在使用短信系统)。
现在我能想到的唯一解决方案是搜索 %0D%0A 并替换为 %0A
I have this string to be encoded (with line break)
Sender ID
Sender ID
Sender ID
When using this urlencode generator, I get the desired output which is
Sender%20ID%0ASender%20ID%0ASender%20ID
However when i using php urlencode() i get this output
Sender+ID%0D%0ASender+ID%0D%0ASender+ID
When using the php rawurlencode() i get this output
Sender%20ID%0D%0ASender%20ID%0D%0ASender%20ID
How to achieve the output same as the generator? I need it to be same since Blackberry phone will properly show line break only if the urlencode for line break is %0A (i am working on a sms system).
Right now the only solution i can think is to search for the %0D%0A and replace with %0A
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您有一个 Windows 行结尾,它由 PHP 直接翻译,并被生成器工具忽略。摆脱它的简单方法就是:
%0D
指的是第 13 个 ASCII 字符:\r
。由于紧随其后的是%0A
(\n
),因此很明显您有 MS 行结尾 (\r\n
)而不是 *nix 行结尾 (\n
) 并且 urlencode 生成器使用 *nix 方法。You have a Windows line ending which is being translated directly by PHP and ignored by your generator tool. The easy way to get rid of it is to simply:
%0D
refers to the 13th ASCII character:\r
. Since this is immediately followed by%0A
(the\n
) it is clear that you have the MS line ending (\r\n
) instead of the *nix line ending (\n
) and that the urlencode generator is using the *nix approach.