Mark Martin
Mark Martin

Reputation: 151

Urlencode & Urldecode in php

On server:

Browser Url--->http://www.mysite.com/?email=external%2Buser%40gmail.com

Email passed in browser--->external%2Buser%40gmail.com 

Email After Encode--->external%5Euser%40gmail.com /* using urlencode function */

Email After Decode--->external^[email protected] /* using urldecode function */

On Localhost:

Browser Url--->http://localhost/test.php?email=external%2Buser%40gmail.com

Email passed in browser--->external%2Buser%40gmail.com

Email After Encode--->external%2Buser%40gmail.com /* using urlencode function */

Email After Decode--->[email protected] /* using urldecode function */

In above code i don't know why server result is different than localhost. on server %2B(+) is converted into %5E(^) while urlencode. I want same result as localhost. Please help me on this.

Upvotes: 1

Views: 6170

Answers (2)

revo
revo

Reputation: 48751

You'd better use rawurldecode() instead of urldecode() and rawurlencode() instead of urlencode().

Upvotes: 2

Akash
Akash

Reputation: 5012

This is most likely to the different character encoding on your server and localhost

Try converting them to a common character set as

urlencode( utf8_decode($strContent) );

Upvotes: 0

Related Questions