Jump to content

[SOLVED] Trim a URL if...


monkeytooth

Recommended Posts

I am working on a function for a site that I am working. The function itself is working fine minus one element. What the concept is, is a user clicks on a link to allow this function to go to its corresponding loading page, runs it script, and then sends the user back to where they were since the ability to use the function is spread out through out the site there is no static means per say of doing it. I have been attempting to use

 

$_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'];

 

To catch the last URL prior to running the function, but I keep getting stuck in an endless loop cause the function looks for a specfic var in the URL to activate and run. So using $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING']; catches that particular var as well so I need a way to trim it out if its in the url but only after the function runs. the var is "theme=xxxxxxx" xxxxxx being anything from 3-16 char long. I have made it so that it appends to the end of the URI everytime however. So anyone any suggestions or ideas as to how I can do this?

Link to comment
https://forums.phpfreaks.com/topic/158121-solved-trim-a-url-if/
Share on other sites

Thank you..

 

I ended up playing a bit and with a little searching combined with the playing I came to this..

 

function remove_querystring_var($url, $key) {
    $url = preg_replace('/(.*)(\?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&');
    $url = substr($url, 0, -1);
    return ($url);
}
$backlink2use = $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'];
$backlink2use = remove_querystring_var($backlink2use, "theme");

Link to comment
https://forums.phpfreaks.com/topic/158121-solved-trim-a-url-if/#findComment-834057
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.