1

I tested urlencode() and rawurlencode() out and they produce different result, like in Firefox and some online encoders...

Example;

Firefox & encoders

ä = %C3%A4
ß = %C3%9F

PHP rawurlencode() and urlencode():

ß = %DF

ä = %E4

What can I do, except hard coding and replacing?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
king
  • 25
  • 3
  • 2
    You need to understand *why* you are seeing this, otherwise "fixing" the problem is only going to result in problems later. See http://stackoverflow.com/q/1549213/50079. – Jon May 07 '11 at 12:46

2 Answers2

3

They produce different outputs because you provided different inputs, i.e., different character encodings: Firefox uses UTF-8 and your PHP script uses Windows-1252. Although in both character sets the characters are at the same position (ß=0xDF, ä=0xE4), i.e., the have the same code point, they encode that code point differently:

 CP   | UTF-8  | Windows-1252
------+--------+--------------
 0xDF | 0xC39F |         0xDF
 0xE4 | 0xC3A4 |         0xE4

Use the same character encoding (preferably UTF-8) and you’ll get the same result.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Gumbo
  • 643,351
  • 109
  • 780
  • 844
  • Thanks gumbo it worked. $str = "hehe näturlich ß"; $out = iconv('ISO-8859-2', 'UTF-8', $str); echo rawurlencode($out); produced result i want... thank you – king May 07 '11 at 13:29
0

Maybe Base64 encode, and use in post, to not make visitors afraid of these URLs.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
publikz.com
  • 931
  • 1
  • 12
  • 22