0

In a php file I typically generate links like this:

<a href="admin.php?t=email&id=3">Edit Primary Email</a>

When I look at this in FireFox's "View Source" window, I notice it highlights it in red, and says "& did not start a character reference", which is true, but is this valid for a query string? It still works (and gets rid of the 'error') if I change it to &amp; but I'm curious now about the official way it should be (which I think is the first).

squidge
  • 444
  • 2
  • 9

2 Answers2

1

Firefox and you are both right.

A query string indeed uses & to separate parameters - but the HTML document requires ampersands to be encoded &amp;.

See Do I really need to encode '&' as '&amp;'? for more background.

Community
  • 1
  • 1
Pekka
  • 418,526
  • 129
  • 929
  • 1,058
1

but is this valid for a query string?

For a query string by itself? No.

For a query string expressed in HTML? Yes.

This is the latter.

Quentin
  • 800,325
  • 104
  • 1,079
  • 1,205