sn0ep
sn0ep

Reputation: 3943

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.

I'm using PHP, a MySQL server and PHPMyAdmin as DB Management tool.

Upvotes: 0

Views: 361

Answers (5)

Marc B
Marc B

Reputation: 360632

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;.

Upvotes: 0

mynameiscoffey
mynameiscoffey

Reputation: 15982

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.

Upvotes: 0

gdub
gdub

Reputation: 301

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

Upvotes: 1

GolezTrol
GolezTrol

Reputation: 116110

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.

Upvotes: 2

tomahaug
tomahaug

Reputation: 1476

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.

Upvotes: 0

Related Questions