开发者

PHP urlencode() and whitespace

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 w开发者_如何学Cill 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


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:

str_replace( "\r\n", "\n", $input );

%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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜