When a user submits a s开发者_JAVA技巧pecial character ♠
it's stored in MySQL database as â�
and if a user wants to change it instead of displaying it back as ♠
its displayed as â�
how can I fix this problem so that its dsiplayed back as ♠
and saved as ♠
?
On a side note how should I save my special characters using PHP?
I'm using PHP & MySQL
- User types in data
- You escape that data to avoid SQL injection (don't convert the special characters to html code equivalent yet)
- Data gets stored in the database exactly how user typed it in
- You pull the raw data back out
- You run the raw data through a character encoding function or something equivalent to convert special characters to their html codes thus avoiding cross site scripting or html injection
That's could be a problem.
If you want to convert your special characters into entities, you have to htmlencode them twice when outputting into field value/textarea content. But it could mess with other characters - all become their entity representations - quotes, brackets and such. If it's what you're asked for - go ahead. But, in my opinion, it could be a terrible mess to edit such a text.
That's why it's better not to let users to use entities. Why can't they enter the symbol itself?
As for the special characters in your database - just use UTF-8 encoding in both database and HTML.
精彩评论