remove a part of a URL argument string in php -


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

  $ String = Http://domain.com/php/doc.php?arg1=0&g2=1&arg3=0  

I want to remove an argument completely and Return the string that is going to be For example, I want to delete arg3 and end it with:

  $ string = http://domain.com/php/doc.php ? Arg1 = 0 & amp; Arg2 = 1  

I would always like to delete the same argument ( arg3 ), and whether this can be the last argument.

Thoughts?

Edit: There may be a bunch of characters in arg3 , so my preferred way to do this (in essence):

 $ String From  $ newstring = remove $ _GET ["arg3"]; There is no real reason to use Regexes, you can use the string and array function instead.  

.

You ? The latter part of (which you can use to get a substrings and can obtain the status of the previous ? ), and arg3 Use to remove, and then to return the string together.

  $ string = "http://domain.com/php/doc.php ARG1 = 0 & amp; aRG2 = 1 & amp3 = 0"; $ Pos = strrpos ($ string, "?"); // Get past status? $ Query_string_parts = array in string; Foreign (explosion ("& amp;", substr ($ string, $ pos + 1)) $ q) {list ($ key, $ val) = explosion ("=", $ q); If ($ key! = "AG3") {// Keep track of the parts that do not have the key $ arguments for $ query_string_parts [] = "$ key = $ val"; }} // string $ result = substr ($ string, 0, $ pos + 1) to be rebuilt ($ Query_string_parts); View this in action on  


Comments