0

I have an application that is getting posted via HTTP GET to and occasionally my users are putting in hash marks (pound signs) and it breaks everything from that point forward in the post. I do not mind at all using javascript or anything else.

Basically, what I want is if the GET URL looks like this: http://some.thing/index.php?addres=123%20main%20st%#20 I want it tojust get rid of the # but keep everything else, so it would end up like: http://some.thing/index.php?addres=123%20main%20st%20

Thanks everyone.

1 Answers1

0

Your example is a postal address, so presumably you actually want that number sign, since it's the number of a unit.

I'm not sure how the %# worked its way in there but I suspect there is some regex trickery to convert spaces into %20 but not other characters that must also be escaped.

Since you're sending a GET request, look into using encodeURIComponent() before sending it:

encodeURIComponent("123 main st #20");
"123%20main%20st%20%2320"

And then decode it in PHP with urldecode().

Community
  • 1
  • 1
msanford
  • 11,803
  • 11
  • 66
  • 93