Reputation: 1462
I'm storing data in a MySQL database that may have some special characters. I'm wondering how to store it so that these characters are preserved if they're either output to HTML via PHP OR via JavaScript, e.g. createTextNode.
For example, the division symbol (÷) has the html code ÷
, and when I store it as that it shows up fine when put directly into HTML by PHP, but when I pull it into JavaScript using $.getJSON and then insert it with createTextNode it shows up looking like ÷
.
I also tried storing the symbol in the SQL directly, but my understanding is that the column would need to be changed from VARCHAR to NVARCHAR and that would cause a performance hit that doesn't seem necessary.
Given that I can modify the SQL, the PHP, or the JavaScript, is there an easy fix here? Maybe a way to unescape the HTML entity in JavaScript?
Upvotes: 1
Views: 1978
Reputation: 3531
So there's probably two things going on:
So you just need to decode the string in your JavaScript, or you need to find what part of your code is URL encoding those strings and fix it.
Upvotes: 0
Reputation: 1220
As answered by Yogesh, you should switch your collation of the DB to utf8_general_ci
Upvotes: 1