4

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

3
  • dude, where is your original query string? Commented Sep 6, 2011 at 6:00
  • 1
    %0D%0A is \r\n. Do str_replace("\r\n","\n",$string). Commented Sep 6, 2011 at 6:00
  • Interesting. A web search for "CRLF on SMS" indeed shows that CRLF is not recognized in some SMS systems. Who'd have thought? (Not that I use Windows....) Commented Sep 6, 2011 at 6:02

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.