JohnDotOwl
JohnDotOwl

Reputation: 3755

URLencoding with specific Charset

When i try this link out "http://www.url-encode-decode.com/" which i use to encode using GB2312, it returns %D4%B2%CD%A8%CB%D9%B5%DD which is what i want. But when i do a normal URL encoding in php using

$urlencoded = urlencode('圆通速递');

it returns

%E5%9C%86%E9%80%9A%E9%80%9F%E9%80%92

Doesnt turn out as what i want. How do i URL encode in a specific charset?

Upvotes: 1

Views: 609

Answers (2)

user557846
user557846

Reputation:

echo urlencode(mb_convert_encoding('圆通速递','GB2312',"auto"));

result:

%D4%B2%CD%A8%CB%D9%B5%DD

Upvotes: 1

Johann Tor
Johann Tor

Reputation: 44

You should try converting the encoding of the string first. Something like this:

$urlencoded = urlencode(mb_convert_encoding('圆通速递','GB2312','UTF-8'));

Upvotes: 1

Related Questions