470,870 Members | 1,416 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,870 developers. It's quick & easy.

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?
Jul 17 '05 #1
3 1739

"chris" <ch***@bemail.org> wrote in message
news:d5**************************@posting.google.c om...
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?


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

Garp
Jul 17 '05 #2
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?

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

Garp

Jul 17 '05 #3
[top-post fixed]

"chris" <ch***@bemail.org> wrote in message
news:d5*************************@posting.google.co m...
Run it through htmlspecialchars() first and it will turn the & into &amp; first, so you get "Chadwick&amp;rsquo;s" in the value field, which looks
like "Chadwick&rsquo;s" in the page.

Garp

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?


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 htmlspecialchars() gives this handy function for doing that,
but remember to handle quotes so that your SQL still works:

function htmldecode($encoded) {
return
strtr($encoded,array_flip(get_html_translation_tab le(HTML_ENTITIES)));
}

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

HTH
Garp
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Scott Matthews | last post: by
3 posts views Thread by Peter | last post: by
reply views Thread by tkcheng | last post: by
4 posts views Thread by Darrel | last post: by
6 posts views Thread by Scirious | last post: by
6 posts views Thread by 7stud | last post: by
1 post views Thread by anonymous | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.