Jump to content

Remove UTM code from URL


jarvis

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/273791-remove-utm-code-from-url/
Share on other sites

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

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.