mac007 Posted March 5, 2009 Share Posted March 5, 2009 Hi, I got this problem, where I need to capture get url variable pairs, but these are coming from an automatically created javascript and has this format: page?custom zip=33021&custom city=boston... and so on... If you notice the actual variable-names have spaces in it (custom zip, custom city; as opposed to normally named customzip, customcity) and when i try to capture them in php like this: <?php echo $_GET['custom zip']; ?> it doesnt do it... But if I manually change my url and join the variables like this: "customzip=33021" and change php accordingly, then it echoes it with no problem! So I think is cause php doesnt like the actual variable to have spaces in it.. so how do I get to read it?? thanks, appreciate feedback... Link to comment https://forums.phpfreaks.com/topic/148126-solved-url-variable-name-itself-has-space-in-it-how-can-i-retrieve-it-in-php/ Share on other sites More sharing options...
revraz Posted March 5, 2009 Share Posted March 5, 2009 Fix the java script. Link to comment https://forums.phpfreaks.com/topic/148126-solved-url-variable-name-itself-has-space-in-it-how-can-i-retrieve-it-in-php/#findComment-777565 Share on other sites More sharing options...
Maq Posted March 5, 2009 Share Posted March 5, 2009 You have to encode it for the URL. You can use the "escape()" function on the string in JS and urldecode() in PHP. Link to comment https://forums.phpfreaks.com/topic/148126-solved-url-variable-name-itself-has-space-in-it-how-can-i-retrieve-it-in-php/#findComment-777580 Share on other sites More sharing options...
revraz Posted March 5, 2009 Share Posted March 5, 2009 If you going into the JS, might as well fix it and add a _ instead of a space. Link to comment https://forums.phpfreaks.com/topic/148126-solved-url-variable-name-itself-has-space-in-it-how-can-i-retrieve-it-in-php/#findComment-777581 Share on other sites More sharing options...
Mchl Posted March 5, 2009 Share Posted March 5, 2009 It's in $_GET['custom_zip'] Link to comment https://forums.phpfreaks.com/topic/148126-solved-url-variable-name-itself-has-space-in-it-how-can-i-retrieve-it-in-php/#findComment-777595 Share on other sites More sharing options...
mac007 Posted March 5, 2009 Author Share Posted March 5, 2009 Thanks Guys... adn Mchl, you are awesome! Your suggestion worked like a charm!! I couldnt believe it was such a simple fix... simply making the space a hiphen did it beautifully. So does PHP automatically pick up spaces as underscores? does that happen only in this case when dealing with variables?? Thanks a lot!! Link to comment https://forums.phpfreaks.com/topic/148126-solved-url-variable-name-itself-has-space-in-it-how-can-i-retrieve-it-in-php/#findComment-777662 Share on other sites More sharing options...
Mchl Posted March 5, 2009 Share Posted March 5, 2009 I think it will work only with GET and POST variables. It will also change other character that are invalid in variable names to underscore. http://www.php.net/manual/en/language.variables.external.php Link to comment https://forums.phpfreaks.com/topic/148126-solved-url-variable-name-itself-has-space-in-it-how-can-i-retrieve-it-in-php/#findComment-777709 Share on other sites More sharing options...
mac007 Posted March 5, 2009 Author Share Posted March 5, 2009 man.. that's a great tip! thanks a lot... Link to comment https://forums.phpfreaks.com/topic/148126-solved-url-variable-name-itself-has-space-in-it-how-can-i-retrieve-it-in-php/#findComment-777715 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.