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?

urlencode function:

<a href="yourpage.php?gallery=<?php echo urlencode("Sand_&_Surf");?>">HM</a>
commented: Here's some green! +16

urlencode function:

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

Worked like a charm. Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.