8

One of my fields (which is a latin1_swedish_ci) seems to show the euro symbol fine in PHPMYADMIN inside of the field.

However, when I try to echo it in an input field on my website in a form, it shows up as the question-mark in firefox.

Heres the html/php:

$sql = mysql_query("select * from `settings`");

while ($row = mysql_fetch_assoc($sql))
    $setting[$row['field']] = htmlspecialchars($row['value'], ENT_QUOTES);

<input type="text" name="currency_symbol" id="currency_symbol" size="50" value="<?php echo $setting['currency_symbol']; ?>" />

I am using the following meta tag on the page:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

I've tried using utf8_general_ci for the field, but I get the same result.

scarhand
  • 4,269
  • 23
  • 63
  • 92

3 Answers3

5

Try using htmlentities() instead of htmlspecialchars().

Special chars does not convert everything, just a few select characters. The Euro symbol €, needs to be encoded really, &euro;.

Orbling
  • 20,413
  • 3
  • 53
  • 64
  • -1 The Euro sign most certainly does not need to be converted to an entity when the character set supports it. In fact, when using Unicode, you virtually never need `htmlentities` instead of `htmlspecialchars`. – Michael Madsen Jul 25 '11 at 00:19
  • @Michael Madsen: Depends if you have setup your language and character code correctly for the document. Firefox does have a tendency to display question marks, particularly for content inserted dynamic unless entity encoded. – Orbling Jul 25 '11 at 03:11
  • @Michael Madsen: Additionally, few people output as Unicode from PHP, so such things get corrupted. PHP still does not handle that automatically, so in practice it is rarely done. – Orbling Jul 25 '11 at 03:12
  • 3
    If you don't have those things setup correctly, then your process is broken, and htmlentities is an ugly hack around the actual problem - namely that you don't have those things set up correctly. I've used UTF-8 with PHP for years now, and not once has htmlentities been necessary. – Michael Madsen Jul 26 '11 at 13:13
  • @Michael Madsen: Depends which standard you are keeping to, if you are still on HTML4, then it is correct procedure. XHTML upwards, entities are a highly compatible way of dealing with the situation, some readers, like text readers, mess up UTF8 still sometimes. Not debating that it is a sensible method, only that the older method is not "wrong". – Orbling Jul 26 '11 at 13:40
4

If you are serving the page as UTF-8, you will need to ensure you grab the string out of the database in the UTF-8 encoding before putting it on the page. You can do that using:

mysql_set_charset('utf8');

(If you're doing that it would also make sense to store your actual table data in UTF-8 too, eg utf8_general_ci, rather than latin1_swedish_ci, so you can deal properly with characters outside of the basic Latin-1 set.)

bobince
  • 528,062
  • 107
  • 651
  • 834
0

Try to change the MySQL charset to UTF-8 or to Swedish.

Here it is a small example.

Master_ex
  • 789
  • 6
  • 12