MYSQL Characters like ( ', ", &) etc. appear different
I'm keeping a database that is filled automaticlly by my users. but when there is an input like My Father's Will
. It will get into the database like: My Father's Will
.
This is not what I want. Can someone tell me how to enable these kinds of special characters or possibly a work around to not show these ugly characters to my users开发者_StackOverflow.
I'm using PHP, a MySQL server and PHPMyAdmin as DB Management tool.
It looks like the '
is escaped like a HTML character. I guess you're doing a wrong escaping, like using htmlentities
instead of mysql_real_escape_string
. If this info doesn't help, please post your code. It will be guessing without.
When you pull the values out of your database, use htmlspecialchars_decode(). This will convert all html special characters back into regular text.
$str = 'My Father's Will';
echo htmlspecialchars_decode($str);
will output:
My Father's Will
I can't really figure what you are asking, since "My Father's Will" and "My Father's Will" is exactly the same?
But it seems like a problem related to either string escaping in PHP or conflicting encoding in the MySQL-database, try to have a look into both and feel free to specify you question a bit more.
It sounds like you might be escaping (such as php's htmlentities()) your input on its way to the database. The correct thing to do would be to instead escape it only on output back to the screen.
Most likely you have a call to htmlspecialchars(..., ENT_QUOTES)
in your code somewhere, which would encode '
and "
into character entities. If they're in the database in encoded form, and the end-user sees the character entities, then you're doing a double-encoding and your script's output is something like &x27;
.
精彩评论