Some text I am entering includes several up and down arrows (↑ and ↓), as well as a plus/minus sign (±).
These special characters are entered as HTML ASCII: ↑ ↓ ±. On POST, the HTML is processed with htmlentities prior to being saved to the MySQL table.
$data = htmlentities($data,ENT_QUOTES);
It is important to note that the up and down arrow symbols are not converted to black arrows. After POSTing data, then going back to edit the same text – I see the ↑ and ↓ in the HTML source code. Only the ± is converted to the black question mark.
Checking the saved text in MySQL confirms that all three symbols are stored as follows (this after htmlentites is applied): ↑ ↓ and ±.
The PHP application then uses unhtmlentities($data) [below] to convert the entities back to symbols. This works fine with ↑ and ↓. Here is where I’m losing ±.
unhtmlentities:
function unhtmlentities ($string) {
// Restores HTML code to inserted data
// use when pulling from Database
$trans_tbl = get_html_translation_table (HTML_ENTITIES);
$trans_tbl = array_flip ($trans_tbl);
return strtr ($string, $trans_tbl);
// $c = unhtmlentities($a);
}
Why would this work fine for uarr and darr, but not with plusmn?
If you still see
±in the source delivered to your browser, but a<?>is displayed, then it is likely your browser’s fault. Check what your Character Encoding is set to.edit: like mario commented, it could also simply be that that character does not exist in the font you are using.