$_GET Help

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
HB-Dave
Forum Newbie
Posts: 2
Joined: Wed Dec 07, 2011 3:00 pm

$_GET Help

Post by HB-Dave »

How do I grab a get variable where the value of the variable may have an "&" sign in it?

For example, for this URL

Code: Select all

//http://example.com/?site=http://www.youtube.com/watch?v=S8zhmiS-1kw&ThisGets=CutOff

echo $_GET["site"];

//returns "http://www.youtube.com/watch?v=S8zhmiS-1kw"
//This, "&ThisGets=CutOff" because of the "&"

//How do I make $_GET["site"]== http://www.youtube.com/watch?v=S8zhmiS-1kw&ThisGets=CutOff
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: $_GET Help

Post by twinedev »

The problem is the URL is not properly formatted for the purpose you are wanting to use here.

$_GET['site'] = 'http://www.youtube.com/watch?v=S8zhmiS-1kw'
and
$_GET['ThisGets']='CutOff';

Whatever is making the link that you gave, it needs urlencode() around the url:

Code: Select all

echo '<a href="http://example.com/?site=' . urlencode($site2pass) .'">Link Text</a>';
see http://php.net/urlencode

-Greg
HB-Dave
Forum Newbie
Posts: 2
Joined: Wed Dec 07, 2011 3:00 pm

Re: $_GET Help

Post by HB-Dave »

Great, that looks like it should work. Thanks for your help!
Post Reply