posting/encode issue

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

    posting/encode issue

    I have a string in a select list.

    value="Chadwick ’s"

    after posting it's changed automatically

    to

    Chadwick's

    How can I stop this?
  • Garp

    #2
    Re: posting/encode issue


    "chris" <chris@bemail.o rg> wrote in message
    news:d57668b9.0 406111932.4889b a22@posting.goo gle.com...[color=blue]
    > I have a string in a select list.
    >
    > value="Chadwick &rsquo;s"
    >
    > after posting it's changed automatically
    >
    > to
    >
    > Chadwick's
    >
    > How can I stop this?[/color]

    Run it through htmlspecialchar s() first and it will turn the & into &amp;
    first, so you get "Chadwick&amp;r squo;s" in the value field, which looks
    like "Chadwick&rsquo ;s" in the page.

    Garp


    Comment

    • chris

      #3
      Re: posting/encode issue

      I'm not gonna show it on a page. It's going to the database. Isn't
      there a way to make PHP from messing with the variable?
      [color=blue]
      >
      > Run it through htmlspecialchar s() first and it will turn the & into &amp;
      > first, so you get "Chadwick&amp;r squo;s" in the value field, which looks
      > like "Chadwick&rsquo ;s" in the page.
      >
      > Garp[/color]

      Comment

      • Garp

        #4
        Re: posting/encode issue

        [top-post fixed]

        "chris" <chris@bemail.o rg> wrote in message
        news:d57668b9.0 406121103.75900 d1@posting.goog le.com...[color=blue][color=green]
        > > Run it through htmlspecialchar s() first and it will turn the & into[/color][/color]
        &amp;[color=blue][color=green]
        > > first, so you get "Chadwick&amp;r squo;s" in the value field, which looks
        > > like "Chadwick&rsquo ;s" in the page.
        > >
        > > Garp[/color]
        > I'm not gonna show it on a page. It's going to the database. Isn't
        > there a way to make PHP from messing with the variable?[/color]

        PHP isn't messing with anything, that's HTTP doing that. Let me check what
        you wanted to fix - you have the correct &-escaped string in the HTML so
        it's going to be visible properly in the listbox, and when you select it and
        get the results, the value of the select control is going to come back
        unaltered. You want to store it in the database in real - i.e. not
        &-escaped - format?

        The help for htmlspecialchar s() gives this handy function for doing that,
        but remember to handle quotes so that your SQL still works:

        function htmldecode($enc oded) {
        return
        strtr($encoded, array_flip(get_ html_translatio n_table(HTML_EN TITIES)));
        }

        Personally, I store all my strings in the database in &-escaped format and
        search strings get the htmlspecialchar s() treatment first.

        HTH
        Garp


        Comment

        Working...