Rifts Posted February 19, 2012 Share Posted February 19, 2012 Hey guys, It's been awhile since I've coded in PHP and I can not for the life of me remember how to do this. Say I have http://www.example.com/search.php?name=joe&size=small What the PHP code to grab the ?name=joe&size=small part? thanks Quote Link to comment https://forums.phpfreaks.com/topic/257322-php-get-url-info/ Share on other sites More sharing options...
PaulRyan Posted February 19, 2012 Share Posted February 19, 2012 You'd probably want to use $_GET like this: <?PHP $name = $_GET['name']; //### Will now be "joe" $size = $_GET['size']; //### Will now be "small" echo 'Name: ' . $name . ' <br>'; echo 'Size: ' . $size; ?> Of course you will have to check to make sure the query paramter exists using isset. Regards, PaulRyan. Quote Link to comment https://forums.phpfreaks.com/topic/257322-php-get-url-info/#findComment-1318974 Share on other sites More sharing options...
requinix Posted February 19, 2012 Share Posted February 19, 2012 A couple more answers since the question is a bit ambiguous: - if that URL is in a string then use parse_url - the whole query string (without the question mark) is in $_SERVER["QUERY_STRING"] Quote Link to comment https://forums.phpfreaks.com/topic/257322-php-get-url-info/#findComment-1318976 Share on other sites More sharing options...
Rifts Posted February 19, 2012 Author Share Posted February 19, 2012 perfect thanks Quote Link to comment https://forums.phpfreaks.com/topic/257322-php-get-url-info/#findComment-1318978 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.