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

  • Home
  • SEARCH
  • 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 202615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:18:20+00:00 2026-05-11T17:18:20+00:00

So, the situation I’m currently in is a wee bit complicated (for me that

  • 0

So, the situation I’m currently in is a wee bit complicated (for me that is), but I’m gonna give it a try.

I would like to run to a snippet of HTML and extract all the links referring to my own domain. Next I want to append these URL’s with a predefined string of GET vars. For example, I want to append ‘?var1=2&var2=4’ to ‘http://www.domain.com/page/‘ thus creating ‘http://www.domain.com/page/?var1=2&var2=4‘.

The method I’m currently applying is a simple preg_replace function (PHP), but here is when it gets interesting. How do i create valid appended url’s when they already have some GET vars at the end? For example, it could create a url like this: ‘http://www.domain.com/page/?already=here&another=one?var1=2&var2=4‘
thus breaking the GET data.

So to conclude, what I’m looking for is a reg exp which can cope with these scenarios, create my extended url and write it back to the HTML snippet.

This is what I have so far:

$sHTML = preg_replace("'href=\"($domainURL.*?[\/$])\"'", 'href="\1' . $appendedTags . '"', $sHTML);

Thanks in advance

  • 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-05-11T17:18:20+00:00Added an answer on May 11, 2026 at 5:18 pm

    In addition to what Elazar Leibovich suggested, I’d parse the query string with parse_str(), modify the resulting array to my needs and then use http_build_query() to rebuild the query string. This way you won’t have any duplicates within your query string and you don’t have to bother yourself with url-encoding your query-parts.

    The complete example would then look like (augmenting Elazar Leibovich code):

    $broken = parse_url($url);
    $query = parse_str($broken['query']);
    $query['var1'] = 1;
    $query['var2'] = 2;
    $broken['query'] = http_build_query($query);
    return $broken['scheme'] . '://' . $broken['host'] . $broken['path'] .
      '?' . $broken['query'] . '#' . $broken['fragment'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Situation I run a build system that executes many builds for many project. To
Situation is that level of log4net is configured as 'Error' but there is some
Situation: I'm implementing a list-like container that supports a Pop() function that should return
Situation is a string that results in something like this: <p>This is some text
Situation: I have a database that contains sales records, each record has a ID
Situation: I have a simple XML document that contains image information. I need to
Situation: text: a string R: a regex that matches part of the string. This
Situation with Thai text on a client site is that we can't control where
Situation: I am trying to write a efficient query using "LIKE" statement to look
Situation: I am writing a program in C that maintains a number of threads.

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.