blic Posted May 19, 2011 Share Posted May 19, 2011 Hi all, I need to get a parameter from an url, but the GET variables are passed through urldecode(). Some of my variables may have characters such as "+", ":", spaces, etc. When I use GET, all "+" are converted to spaces. I can use urlencode to get the "+" back, but also everything that was previously a space also turns into "+". Example: variable = abc+ c+ Then I can get either: abc c or abc++c+ but I want to get abc+ c+ Would anybody know how to help me? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/236809-help-getting-parameters-correctly-from-url/ Share on other sites More sharing options...
QuickOldCar Posted May 19, 2011 Share Posted May 19, 2011 urldecode() + $_GET = Bad Quote Link to comment https://forums.phpfreaks.com/topic/236809-help-getting-parameters-correctly-from-url/#findComment-1217345 Share on other sites More sharing options...
blic Posted May 19, 2011 Author Share Posted May 19, 2011 _GET does urldecode automatically.. I do enconde, in order to get the "+", but all original spaces also becomes "+" that's my problem. I want to get the original "+" as well as the spaces Quote Link to comment https://forums.phpfreaks.com/topic/236809-help-getting-parameters-correctly-from-url/#findComment-1217347 Share on other sites More sharing options...
sasa Posted May 19, 2011 Share Posted May 19, 2011 use urlencode() function on variable before put it in link and urldecode() on $_GET variable Quote Link to comment https://forums.phpfreaks.com/topic/236809-help-getting-parameters-correctly-from-url/#findComment-1217349 Share on other sites More sharing options...
QuickOldCar Posted May 19, 2011 Share Posted May 19, 2011 Or alternately can use http://us.php.net/rawurldecode and http://php.net/manual/en/function.rawurlencode.php example: <?php $url = "http://somesite.com/My File/script.php?value=1+2+3+4"; $decode = rawurldecode($url); $encode = rawurlencode($decode); echo $url."<br />"; echo $decode."<br />"; echo $encode."<br />"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/236809-help-getting-parameters-correctly-from-url/#findComment-1217350 Share on other sites More sharing options...
blic Posted May 19, 2011 Author Share Posted May 19, 2011 thanks for the reply.. I know it works when there's only + But when there's + and spaces is when it get's confused.. Try the same example but instead of value=1+2+3+4 try value=1+2 +3+4 the space after "2" is the one I can't get.. Quote Link to comment https://forums.phpfreaks.com/topic/236809-help-getting-parameters-correctly-from-url/#findComment-1217352 Share on other sites More sharing options...
sasa Posted May 19, 2011 Share Posted May 19, 2011 try <?php $a='sasa + sasa'; echo '<a href="?data='. urlencode($a).'">click me</a>'."<br />\n"; if (isset ($_GET)) echo $_GET['data']; ?> script just generate link with + and space, and echo result Quote Link to comment https://forums.phpfreaks.com/topic/236809-help-getting-parameters-correctly-from-url/#findComment-1217363 Share on other sites More sharing options...
blic Posted May 19, 2011 Author Share Posted May 19, 2011 Thank you all! It worked.. Quote Link to comment https://forums.phpfreaks.com/topic/236809-help-getting-parameters-correctly-from-url/#findComment-1217540 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.