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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:36:15+00:00 2026-05-17T00:36:15+00:00

I have a string in PHP that is a URI with all arguments: $string

  • 0

I have a string in PHP that is a URI with all arguments:

$string = http://domain.com/php/doc.php?arg1=0&arg2=1&arg3=0

I want to completely remove an argument and return the remain string. For example I want to remove arg3 and end up with:

$string = http://domain.com/php/doc.php?arg1=0&arg2=1

I will always want to remove the same argument (arg3), and it may or not be the last argument.

Thoughts?

EDIT: there might be a bunch of wierd characters in arg3 so my prefered way to do this (in essence) would be:

$newstring = remove $_GET["arg3"] from $string;
  • 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-17T00:36:16+00:00Added an answer on May 17, 2026 at 12:36 am

    There’s no real reason to use regexes here, you can use string and array functions instead.

    You can explode the part after the ? (which you can get using substr to get a substring and strrpos to get the position of the last ?) into an array, and use unset to remove arg3, and then join to put the string back together.:

    $string = "http://domain.com/php/doc.php?arg1=0&arg2=1&arg3=0";
    $pos = strrpos($string, "?"); // get the position of the last ? in the string
    $query_string_parts = array();
    
    foreach (explode("&", substr($string, $pos + 1)) as $q)
    {
      list($key, $val) = explode("=", $q);
      if ($key != "arg3")
      {
        // keep track of the parts that don't have arg3 as the key
        $query_string_parts[] = "$key=$val";
      }
    }
    
    // rebuild the string
    $result = substr($string, 0, $pos + 1) . join($query_string_parts);
    

    See it in action at http://www.ideone.com/PrO0a

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

Sidebar

Related Questions

I have an url like this: http://www.w3schools.com/PHP/func_string_str_split.asp I want to split that url to
I have a string that I want to have PHP read as a piece
I have a PHP script that does basic encryption of a string through the
I have a function to grab the current url - found here: http://webcheatsheet.com/php/get_current_page_url.php -
i have string (uri) that i need to decode in c++ , its have
Can anyone help? I have a PHP method that sends an http post: <?php
I have a php script that grabs links from another website. I am storing
I have sorted list of strings that I move between php and java. to
I have this string in php i want to skip the ppattern ------------------------------------------ FROM:Andy;
I have a string in PHP and I want it to match the regex

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.