Url Encoding - Use rawurlencode not urlencode !

The URL encoding is one the mysterious functions that PHP programmers does use but without knowing all the details behind it. When one wants to create a link dynamically he just use urlencode, and thi is so necessary because in an URl, there is some reserved characters that have sens for the browsers and the the server-side scripts. You should already know the meaning of ? , & and = characters in the query string, if you don't know see this important Wikipedia article http://en.wikipedia.org/wiki/Query_string

But, you may see somewhere that there is a function called rawurlencode, what is that ? Is it a different encoding convention ? The answer is yes and not.
Well, urlencode and rawurlencode are very similar, they do the same encoding except for one character, the Space character !
rawurlencode encodes the space character as %20, while urlencode encodes it as +, here are few use-difference between both, as much as I understand:

1-Path vs Query vars
In the url path, you should encode spaces as %20 and not +, for example if your folder is called "folder one"
this url will work http://www.exemple.com/folder%20one/index.php , and this will not : http://www.exemple.com/folder+one/index.php because in this last the server will search for a folder called folder+one instead of folder one .
But in the GET variables you should prefer the + character to simulate the space, this is what Google is doing ! But whether you use + or %20 in those url variables, ie you use urlencode or rawurlencode, they should both work.

2-PHP vs JavaScript:
Javascript uses the same convention as rawurlencode, so if you want to encode an url with php but you will decode it in javascript, you should use rawurlencode, and here is the reason:

Lets say you encoded "test 1" within php, if you need to "decode" it in JavaScript using decodeURI() function then decodeURI("test+1") will give you "test+1" while decodeURI("test%201") will give you "test 1" as result.

Summary:
The rawurlencode function is the last one, and it should work perfectly in modern systems with less problem. So this is the encoding function to use most of the time ! While urlencode is kept for legacy compatibility, as well as compatibility with Javascript.

18 comments:

d3 gold said...

Well, to the gossip put off, we get down to business!

LOL elo boosting said...

not just is the idea very amazing, however it is really nicely performed -- i really like all your sketches, they're therefore stunning to check out! contributing to my personal book marks.

elo boost


Cheap Fifa 14 Coins

Unknown said...

Your posts is really helpful for me.Thanks for your wonderful post.It is really very helpful for us and I have gathered some important information from this blog.



SEO Training in Chennai

Unknown said...

Thanks for sharing the valuable information here. So i think i got some useful information with this content. Thank you and please keep update like this informative details.

Dotnet Training in Chennai

Shalini said...

That was a great message in my carrier, and It's wonderful commands like mind relaxes with understand words of knowledge by information's.

digital marketing company in chennai
seo company in chennai


Samsun cilingir said...

Selam yonetici admin siteniz cok guzel basarilarinizin devamini bekleriz

CIITNOIDA - Best Oracle and linux training institute in noida delhi ncr said...

Top MCA

colleges in greater noida

Top MSC IT

colleges in greater noida

Top M

TECH colleges in greater noida

nilashri said...

It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...

Devops training in Chennai

Devops training in Bangalore

Devops training in Pune

Devops training in Online

Devops training in Pune

Devops training in Bangalore

Devops training in tambaram

Devops training in OMR

simbu said...

Thank you for benefiting from time to focus on this kind of, I feel firmly about it and also really like comprehending far more with this particular subject matter. In case doable, when you get know-how, is it possible to thoughts modernizing your site together with far more details? It’s extremely useful to me 

java training in annanagar | java training in chennai

java training in marathahalli | java training in btm layout

java training in rajaji nagar | java training in jayanagar

simbu said...

Really great post, Thank you for sharing This knowledge.Excellently written article, if only all bloggers offered the same level of content as you, the internet would be a much better place. Please keep it up!

java training in chennai | java training in bangalore

java online training | java training in pune

selenium training in chennai

selenium training in bangalore

Mounika said...

Woah this blog is wonderful i like studying your posts. Keep up the great work! You understand, lots of persons are hunting around for this info, you could help them greatly.
python online training
python training in OMR
python training course in chennai

Anonymous said...

I am really very happy to find this particular site. I just wanted to say thank you for this huge read!! I absolutely enjoying every petite bit of it and I have you bookmarked to test out new substance you post.
angularjs online Training

angularjs Training in marathahalli

angularjs interview questions and answers

angularjs Training in bangalore

angularjs Training in bangalore

angularjs Training in chennai

Anonymous said...

It was worth visiting your blog and I have bookmarked your blog. Hope to visit again
angularjs Training in electronic-city

angularjs online Training

angularjs Training in marathahalli

angularjs interview questions and answers

angularjs Training in bangalore

angularjs Training in bangalore

swara Misra said...

Here is the site(bcomexamresult.in) where you get all Bcom Exam Results. This site helps to clear your all query.
BA 3rd year Result 2019-20
University of Gour Banga BCOM 3rd Year Result 2020

jimu jee said...


offshoreservers netYouve got an awful lot of text for only having one or two pictures. Maybe you could space it out better?

Kito Infocom said...


Thanks for Sharing Great post

Buy Plants Online in India
Hoya Kerrii, Heart Leaf Plant
Buy Handicrafts Online
Moon Cactus

Book Resin Planter

Buy Planter Pot & Flower Stands
Buy
Succulents & Cactus

Buy Planter Pot & Flower Stands

Admit Card for B.Com Part 1 Exam said...

I am really really impressed with your writing skills as well as with the layout on your blog.

ba result said...

I always spent my half an hour to read this webpage’s content every day along with a cup of coffee.

ba 1st year result, ba 2nd year result, ba 3rd year result.