开发者

URL encoding PHP

开发者 https://www.devze.com 2023-03-04 13:28 出处:网络
I tested urlencode() and rawurlencode() out and they produce different result, like in Firefox and some online en开发者_如何学Gocoders...

I tested urlencode() and rawurlencode() out and they produce different result, like in Firefox and some online en开发者_如何学Gocoders...

Example;

Firefox & encoders

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

PHP rawurlencode() and urlencode():

ß = %DF

ä = %E4

What can I do, except hard coding and replacing?


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.


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

0

精彩评论

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