Why use & in urls?

Why use & in urls?

by Ian Nisbet -
Number of replies: 2

I am starting to dabble with making small modifications to my moodle implementation's code, but I have come across and inconsistency that I cannot explain:

When a url is called directly form a JS function it's querystring has & between each variable, but when it is passed from an OnClick event handler, or is in the href= parameter, then it appears as &

for example in /mod/resource/type/file/resource.class.php
Line 326: openpopup('/mod/resource/view.php?inpopup=true&id={$cm->id}',

whereas 
Line 334: openpopup('/mod/resource/view.php?inpopup=true&id={$cm->id}'

Could anyone please explain why this is?

Thanks

Average of ratings: -
In reply to Ian Nisbet

Re: Why use & in urls?

by Mauno Korpelainen -

You use question mark ( ? ) to start the variable data pair and after that you are separating each variable data pair with one ampersand ( & ) mark - so when you have more than one variable to pass you need & to render & to separate these variable data pairs smile

In reply to Ian Nisbet

Re: Why use & in urls?

by Stephen Mc Guinness -

Hello Ian,

& is the HTML entity for &, and should be used in HTML documents.  & is correct for  use in URLs used directly in the browser address bar, since the address bar is not HTML, but & should be used in the HTML docs.

Stephen Mc Guinness
Enovation Solutions