Pregunta

I am using w3c validator with html5. I have an array afilter[]=abc I am passing in the href and I have tried escaping the brackets as follows:

<a href='slideshowform.php?x=y&amp;afilter&#91;&#93;=abc'>phases of matter</a>

But I am still getting the error:

 Bad value slideshowform.php?x=y&afilter[]=abc for attribute href on element a: Illegal character in query component.

How can I pass an array without getting errors - or did I escape the brackets incorrectly?

¿Fue útil?

Solución

You have to URL encode it, not HTML encode it. Your URL would have to look like the following:

slideshowform.php?x=y&afilter%5B%5D=abc

Most programming languages have stuff like this built in (e.g. rawurlencode() in PHP or encodeURI in JavaScript) or you can simply use an online service like (no affiliation, just one of the first search results) http://www.url-encode-decode.com/

Of course it’s a good idea to encode the HTML reserved characters for outputting the link in an HTML document as well. So you’d end up with the following URL within your HTML document.

slideshowform.php?x=y&amp;afilter%5B%5D=abc
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top