freakstyling Posted March 14, 2012 Share Posted March 14, 2012 Hi people! So what I can´t figure out in this function, which length I should put in. To explain it bit more. After I press the link, I get a querystring. When I press again, I want the old string to disappear. So ?lang=es needs to go, that´s a -8 right? <?php function parseQueryString(){ parse_str($_SERVER['QUERY_STRING']); if(isset($l)){ return substr($_SERVER['QUERY_STRING']-; }else{ return $_SERVER['QUERY_STRING']; } } // ?l=es<?php echo '&'.parseQueryString() ?> <div class="footer"> <div class="back_footer"> <ul> <li><a id="esp" href="?lang=es<?php echo '&'.parseQueryString()?>">ES</a></li> <li><a id="eng" href="?lang=en<?php echo '&'.parseQueryString()?>">EN</a></li> </ul> </div> </div> Thank you! Laurens Quote Link to comment https://forums.phpfreaks.com/topic/258923-problem-with-substr/ Share on other sites More sharing options...
ManiacDan Posted March 14, 2012 Share Posted March 14, 2012 First of all, there's almost certainly a better solution than what you're doing. Secondly, what ARE you doing? You want a single page to reload itself without the query string? Third, what is $l and why do you think it will be populated? Quote Link to comment https://forums.phpfreaks.com/topic/258923-problem-with-substr/#findComment-1327379 Share on other sites More sharing options...
freakstyling Posted March 14, 2012 Author Share Posted March 14, 2012 Solved!! Thanks to you... it was your third part which solved it. I have to start looking at my scripts a bit better. There must be a much better solution, I´ll start with that in a while. Again, thank you! Quote Link to comment https://forums.phpfreaks.com/topic/258923-problem-with-substr/#findComment-1327438 Share on other sites More sharing options...
PFMaBiSmAd Posted March 14, 2012 Share Posted March 14, 2012 If you are trying to build links with specific values for the lang=xx parameter (or even removing/unsetting the lang=xx parameter) while keeping the remainder of the query string as is, I have found that using http_build_query with the $_GET array as its source array is more straight forward. You can just assign values to the appropriate $_GET index or unset the appropriate $_GET index, then append the query string that http_build_query returns onto the end of the url. The values will already be urlencoded and you can specify '&' as the separator since you are outputting the links on a web page (rather than using them in a redirect.) Quote Link to comment https://forums.phpfreaks.com/topic/258923-problem-with-substr/#findComment-1327442 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.