By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,949 Members | 1,855 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,949 IT Pros & Developers. It's quick & easy.

posting/encode issue

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a

"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

P: n/a
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

P: n/a
[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.