How do I do this

Discussion in 'PHP' started by alhermette, Sep 30, 2008.

  1. #1
    I have some query strings in which I need to remove one variable completely before passing it on. The variable in question is "d" and I do not know what other variables may be in the query string at any given time.

    I first did a simple replace of $d and the text "d=" and thought that it would be OK. I have had a few problems though as in the example below:

    ?d=228&f=plastic&h=large&gclid=blahblahblah

    With my replacements I inadvertently removed part of another variable, destroying it in the process (shown in bold).

    What function can I use to replace a whole variable (text and value) in one piece so to speak so that I do not have this error in future.
     
    alhermette, Sep 30, 2008 IP
  2. algaidaman

    algaidaman Active Member

    Messages:
    106
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #2
    This should be a good start for you.

    If the value after the d= is always a fixed length, things will be easier for you to code, but if it is a variable length, you will need to calculate the strpos() in order to remove the entire substring and make the replacement. The good news is that the variable d will always either have a ? or a & in front of it followed by an equals sign.
     
    algaidaman, Oct 1, 2008 IP
  3. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #3
    Is that part of url? If so just use $_GET
     
    Kaizoku, Oct 1, 2008 IP