Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8909707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:30:03+00:00 2026-06-15T03:30:03+00:00

I’ve been breaking my head with a hammer to figure this out but here

  • 0

I’ve been breaking my head with a hammer to figure this out but here goes. I’m currently scraping some pages that I get from various source and the URLs often have Google Analytics crap attached to the end of it, in this fashion:

&utm_medium=something&utm_source=other

And I’m trying to get rid of those from a URL. Since these are appended at the end of a URL, I do this:

 $pattern = "^utm_source.*^";
 $interUrl = preg_replace($pattern, '', $url);

utm_source is a required portion of the URL for google analytics. Here’s my problem shows up. For some reason, I can’t get the pattern to match an ampersand like so: “^\&utm_source.*^”. Without the ampersand (and its escape), I get matches. So I thought “no biggie, I’ll just to a substr” like so:

 $finalUrl = substr($interUrl, 0, strlen($interUrl) - 1);

But nothing happens. I increased the -1 number to -3 or even -4 but nothing got cut off, not even characters after the ampersand. I’ve also tried str_replace and even rtrim but none could filter out the ampersand. This is frustrating since I am left with the wrong URL. Not only that, when I try to curl the page, I get a 404 while if I go to that site via my browser, i get redirected to the right page.

Any ideas on why this is happening?

ANSWER

While all the answers were nice and technical, I kept trying shit with the regex until I figured something out. The URLs were, for some reason (probably my retrieval method), being encoded so I ended up tweaking the regex like so:

$pattern = "/&utm_source.*/";

and it works! Thanks for everyone’s help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:30:04+00:00Added an answer on June 15, 2026 at 3:30 am

    While all the answers were nice and technical, I kept trying shit with the regex until I figured something out. The URLs were, for some reason (probably my retrieval method), being encoded so I ended up tweaking the regex like so:

    $pattern = "/&utm_source.*/";
    

    And it works.

    Why didn’t I catch it earlier? I’m running my app on laravel and whenever I use the logging system, it seems to use an actual ampersand instead of & thus it seemed like all was well.

    At one point, I went to check the database as to what was happening and noticed that my URLs were ending with & instead of with & (it showed up this way on my view).

    Thanks everyone!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
For some reason, after submitting a string like this Jack’s Spindle from a text
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.