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! 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 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 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 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 />"; ?> 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.. 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 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.. 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
Archived
This topic is now archived and is closed to further replies.