Jump to content

Problem with substr( )


freakstyling

Recommended Posts

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']-8);

}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

Link to comment
https://forums.phpfreaks.com/topic/258923-problem-with-substr/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/258923-problem-with-substr/#findComment-1327379
Share on other sites

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.)

 

Link to comment
https://forums.phpfreaks.com/topic/258923-problem-with-substr/#findComment-1327442
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.