Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    stripslashes() eats quotation marks?

    Hi,

    After using addslashes() to the inputs to some text fields, I need to remove them for display. When I use stripslashes() to do so, the strings with single quotes comes out fine, but in the strings with quotation marks, the quotation mark itself and any text following it do not appear. Any ideas why not?

    Here's the code:

    $answer01 = stripslashes($answer);
    $input = "<input type=text name=answer value=\"$answer01\">";
    $patterns = '/<_>/';

    $name = preg_replace($patterns, $input, $title);


    using this:
    isn\'t comes out isn't
    bears\" comes out bears

    Thanks for your help.

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    if you look at the html source, do you see the rest of the text? if your string were:
    she said "look at those bears"
    then the output will be:
    Code:
    <input type=text name=answer value="she said "look at those bears">
    which isn't valid html

  • #3
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Yes

    Thanks for answering. Yes, I sure do. I'm using the quotation marks in the input so all the words in the string appear. Without them, only the first word shows up.

  • #4
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Here's the solution

    NogDog provided this, which turns out the work perfectly:

    "
    If you're going to output a string between double-quotes as a HTML attribute value, then any double-quotes within that string will have to either be escaped, or replaced with the applicable HTML entity:

    PHP Code:
    $answer01 = stripslashes($answer);
    $input = "<input type=text name=answer value=\"".htmlspecialchars($answer01)."\">";





    "


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •