Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL Encoding—Ampersand Problem

Tags:

urlencode

modx

I'm having some trouble with some character encoding causing some problems with a search form on my website. One of the possible field values has an ampersand in it. When this is selected and a search is submitted the ampersand is encoded to: %2526

Upon using the pagination links at the bottom of the page and navigating to the second page in the list of results the ampersand is encoded to: %26

Finally...in an attempt to navigate to the 3rd page in the list the ampersand is changed back to: & This breaks the form as it assumes there's a variable that isn't actually there.

Why is the encoding changing? How can I fix this? Thanks for your help!

like image 838
Vecta Avatar asked Aug 10 '11 14:08

Vecta


People also ask

What does ampersand mean in URL?

Constructing URL Variables & - The ampersand is used before each subsequent variable/value pair in the query string. = - The equals sign separates the variable from the value assigned to that variable.

How do you escape ampersand in HTML?

If you want one to appear in text on a web page you should use the encoded named entity “ & ”—more technical mumbo-jumbo at w3c.org. While most web browsers will let you get away without encoding them, stuff can get dicey in weird edge cases and fail completely in XML.

What does %20 replace in URL?

URL Encoding (Percent Encoding) URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits. URLs cannot contain spaces. URL encoding normally replaces a space with a plus (+) sign or with %20.


2 Answers

It looks like the field is being encoded twice. First pass will result in & changed into %26, then urlencoding %26 will result in %2526, since the encoding for % itself is %25.

like image 89
Andrew Lee Avatar answered Oct 13 '22 09:10

Andrew Lee


If you want to use Andaman & Nicobar in web API.

You can use instead of & you can use %26 and whole will be written as below.

Andaman+%26+Nicobar

like image 36
Pankaj Lahoti Avatar answered Oct 13 '22 08:10

Pankaj Lahoti