how can i pass string with "&" in url use $_g

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
EXDev
Forum Newbie
Posts: 7
Joined: Sun Feb 23, 2003 9:05 am

how can i pass string with "&" in url use $_g

Post by EXDev »

I'm trying to pass a string with an "&" in the middle from url, but when i use $_GET["name"] to retrive the value, it cuts off whatever append to the "&" of the string
so its like when using http://aaa.com?name=abc&abc in the url bar,
$_GET["name"] will only return abc instead of abc&abc
anyone know why and how to fix it
thanks
User avatar
daven
Forum Contributor
Posts: 332
Joined: Tue Dec 17, 2002 1:29 pm
Location: Gaithersburg, MD
Contact:

Post by daven »

you need to use the HTML code for ampersands. Try encoding the URL with htmlspecialchars(). It should work correctly then
EXDev
Forum Newbie
Posts: 7
Joined: Sun Feb 23, 2003 9:05 am

Post by EXDev »

thanks
just figure out what the problems is. when the string pass thur url, the broswer consider the "&" as "variable separator", like ...com?name=abc&pass=123.
so when i try to pass the string "abc&abc" by ...com?name=abc&123, the broswer thinks the first variable is name and second is 123, so when i use $_GET["name"], it only gives me abc.
User avatar
daven
Forum Contributor
Posts: 332
Joined: Tue Dec 17, 2002 1:29 pm
Location: Gaithersburg, MD
Contact:

Post by daven »

Exactly. You cannot have things like ampersands (&), question marks (?), or other such things in a query string, as HTML uses them for variable declaration.
Post Reply