jarvis Posted January 29, 2013 Share Posted January 29, 2013 (edited) I really hope someone can help! I currently use the following to get a URL: $pageURL=''; $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; $filename = basename($pageURL); I could then echo $filename and use it elsewhere in my code. However, I've an issue with the a URL that contains Googles UTM code, for example: http://www.domain.co.uk/2013/02/14/?utm_source=COMPANY&utm_medium=email&utm_term=NewsletterLink&utm_campaign=Newsletter&utm_content= How can I use the above but strip out the ?utm... I've tried a preg_replace but couldn't seem to get it working. Any help is much appreciated! TIA Edited January 29, 2013 by jarvis Quote Link to comment https://forums.phpfreaks.com/topic/273791-remove-utm-code-from-url/ Share on other sites More sharing options...
Psycho Posted January 29, 2013 Share Posted January 29, 2013 parse_url Quote Link to comment https://forums.phpfreaks.com/topic/273791-remove-utm-code-from-url/#findComment-1408972 Share on other sites More sharing options...
requinix Posted January 29, 2013 Share Posted January 29, 2013 Look in $_SERVER for something like the REQUEST_URI but that doesn't contain the query string. For the query string, $get = $_GET; if (isset($get["utm_source"])) unset($get["utm_source"]); // etc if ($get) $url .= "?" . http_build_query($get); Quote Link to comment https://forums.phpfreaks.com/topic/273791-remove-utm-code-from-url/#findComment-1409006 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.