Displaying " in a form text box

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • monomaniac21

    Displaying " in a form text box

    Hi all ive added a form to a script using php and the form is to hold
    sizes of a product which means the client needs to be able to use " to
    denote inches. However when this is entered and the form submitted it
    makes it into the table and then displays as text on the page but not
    inside the form as its value. Is there a way around this?

    Ive tried replacing " with ' and a ' together but can't get this to
    work in the str_replace funtion example: str_replace('"' , '''',
    $string); and help would be greatly appeciated!

    Kind regards

    Marc

  • Rik

    #2
    Re: Displaying " in a form text box

    monomaniac21 wrote:[color=blue]
    > Hi all ive added a form to a script using php and the form is to hold
    > sizes of a product which means the client needs to be able to use " to
    > denote inches. However when this is entered and the form submitted it
    > makes it into the table and then displays as text on the page but not
    > inside the form as its value. Is there a way around this?[/color]

    htmlspecialchar s($string);

    Among others, it will replace '"' with '"'
    [color=blue]
    > Ive tried replacing " with ' and a ' together but can't get this to
    > work in the str_replace funtion example: str_replace('"' , '''',
    > $string); and help would be greatly appeciated![/color]


    Ugly solution, but here;s how it would work:
    str_replace('"' , '\'\'',$string) ;
    or
    str_replace('"' , "''",$strin g);

    Grtz,
    --
    Rik Wasmus


    Comment

    • Geoff Berrow

      #3
      Re: Displaying " in a form text box

      Message-ID: <e11b7$449ff207 $8259c69c$16278 @news1.tudelft. nl> from Rik
      contained the following:
      [color=blue]
      >htmlspecialcha rs($string);
      >
      >Among others, it will replace '"' with '&quot;'[/color]

      Don't you need to do this?

      htmlspecialchar s($string, ENT_QUOTES);

      --
      Regards,

      Geoff Berrow

      Comment

      • Rik

        #4
        Re: Displaying &quot; in a form text box

        Geoff Berrow wrote:[color=blue]
        > Message-ID: <e11b7$449ff207 $8259c69c$16278 @news1.tudelft. nl> from Rik
        > contained the following:
        >[color=green]
        >> htmlspecialchar s($string);
        >>
        >> Among others, it will replace '"' with '&quot;'[/color]
        >
        > Don't you need to do this?
        >
        > htmlspecialchar s($string, ENT_QUOTES);[/color]

        Default is ENT_COMPAT, which only translates double quotes, which would be
        sufficient in this particular case. ENT_QUOTES will also translate the
        single quotes, which is not strictly neccessary here, but might be a good
        idea indeed.

        Grtz,
        --
        Rik Wasmus


        Comment

        Working...