Passing a Quote to explode()

Discussion in 'PHP' started by bloard, May 17, 2006.

  1. #1
    I have a form on page1 that has a text form element. I post the data to page2.php. On page 2.php, I capure the input from the form as a variable: $variable, then place it in an explode() function like this $array=explode('$variable',$r);

    Everything works great... but the problem is, that I want to pass a " (quote) from the form to the explode function. When I do this, the quote is always preceeded by the \ which somehow gets passed by default from the form. I understand using the \ in explode functions, but in this instance don't want it. I just want the " by iteself. How can I do this?

    Thanks
     
    bloard, May 17, 2006 IP
  2. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This will do the trick:

    $variable = stripslashes($variable);
     
    clancey, May 17, 2006 IP
  3. bloard

    bloard Peon

    Messages:
    180
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks... but one more question... When I then put $variable back into a form as a hidden field to be picked up on the third page (Page one is where the variable is entered, passes through text form to page 2. Used in page2 in an explode function - after stripslashes, and then placed as a "hidden" field in a form on page 2 to be passed to page3) will I need to stripslashes again on page 3, or will it pass through the hidden field without the slash being added?
     
    bloard, May 17, 2006 IP
  4. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you're going to be passing from page 1 -> page 2 -> page 3 etc., I'd look at using sessions. That way, you only need to get it from page 1 and then the server will remember from then on...
     
    TwistMyArm, May 18, 2006 IP
  5. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Actually, stripslashes() is the opposite of addslashes(). When a user inputs data into a form, they do not normally put in the slashes. Nor does their web browser. This is done by php using addslashes().

    Hidden field values are bounded by quotation marks, quotations in the hidden value need to be escaped by adding slashes so that they can be correctly parsed.

    TwistMyArm is correct in saying this is a inelegent approach to the problem. There may be other solutions. But, if you want to pass the data through a series of forms as hidden field data, you may not want to strip out the slashes until you are done addint it back in.
     
    clancey, May 18, 2006 IP