Jump to content

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

Edited by jarvis
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);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.