954,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

HTML link contains '&' as part of a string, not a separator

I have a webpage that is passed a string:

http://www.mywebsite.com/gallery.php?gallery=Sand_&_Surf


Using the GET method, I am trying to do this:

$gallery = $_GET['gallery'];


I want to store "Sand_&_Surf" in the $gallery variable. From there, I do a database query and display all the paintings that are for sale in the "Sand & Surf" gallery. the problem is that '&' is a separator for the GET command, so what ends up in $gallery is Sand_ .

Ideas of solving this have included changing '&' to "AMPERSAND" in the link, GETTING it, then converting it back. Is that the way to go or is there a better way?

VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
 

urlencode function:

<a href="yourpage.php?gallery=<?php echo urlencode("Sand_&_Surf");?>">HM</a>
__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

urlencode function:

<a href="yourpage.php?gallery=<?php echo urlencode("Sand_&_Surf");?>">HM</a>

Worked like a charm. Thank you.

VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You