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 214629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:23:34+00:00 2026-05-11T18:23:34+00:00

when we add a param to the URL $redirectURL = $printPageURL . ?mode=1; it

  • 0

when we add a param to the URL

$redirectURL = $printPageURL . “?mode=1”;

it works if $printPageURL is “http://www.somesite.com/print.php“, but if $printPageURL is changed in the global file to “http://www.somesite.com/print.php?newUser=1“, then the URL becomes badly formed. If the project has 300 files and there are 30 files that append param this way, we need to change all 30 files.

the same if we append using “&mode=1” and $printPageURL changes from “http://www.somesite.com/print.php?new=1” to “http://www.somesite.com/print.php“, then the URL is also badly formed.

is there a library in PHP that will automatically handle the “?” and “&”, and even checks that existing param exists already and removed that one because it will be replaced by the later one and it is not good if the URL keeps on growing longer?

Update: of the several helpful answers, there seems to be no pre-existing function addParam($url, $newParam) so that we don’t need to write it?

  • 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-11T18:23:34+00:00Added an answer on May 11, 2026 at 6:23 pm

    Use a combination of parse_url() to explode the URL, parse_str() to explode the query string and http_build_query() to rebuild the querystring. After that you can rebuild the whole url from its original fragments you get from parse_url() and the new query string you built with http_build_query(). As the querystring gets exploded into an associative array (key-value-pairs) modifying the query is as easy as modifying an array in PHP.

    EDIT

    $query = parse_url('http://www.somesite.com/print.php?mode=1&newUser=1', PHP_URL_QUERY);
    // $query = "mode=1&newUser=1"
    $params = array();
    parse_str($query, $params);
    /*
     * $params = array(
     *     'mode'    => '1'
     *     'newUser' => '1'
     * )
     */
    unset($params['newUser']);
    $params['mode'] = 2;
    $params['done'] = 1;
    $query = http_build_query($params);
    // $query = "mode=2&done=1"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 172k
  • Answers 172k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It is indeed a fact of life that multithreaded use… May 12, 2026 at 2:31 pm
  • Editorial Team
    Editorial Team added an answer I have had problems debugging binaries on the device via… May 12, 2026 at 2:31 pm
  • Editorial Team
    Editorial Team added an answer First you want to use the overloaded SslStream constructor: SslStream(Stream… May 12, 2026 at 2:31 pm

Related Questions

It's no question that we should code our applications to protect themselves against malicious,
I'm attempting to create a hierarchal menu system in rails. My menu model is
Env: .NET 1.1 I got into this situation. Where I need to give a
I imagine that we all (when we can be bothered!) comment our interfaces. e.g.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.