0

I have a problem displaying "€" in my html...

  1. My database field has collation "utf8_general_ci"
  2. I fetch the data like that into an javascript variable:

    $query = mysqli_query($con, "SELECT * FROM Table WHERE Id = '1'"); $data = mysqli_fetch_assoc($query);

    $data = json_encode(utf8_encode(($data["Field"])));
    

As I want to echo $data... I get Umlauts see "ÄüÖü" and other chars like " ', #@&" etc. BUT I DON'T SEE THE SIGN..... it get's displayed as a ? ( Not that in a rectangle... just a normal ?)

Can anyone help please?

Btw, that's my header:

header("Content-Type: text/html; charset=utf-8");
Inkperial
  • 73
  • 1
  • 8
  • 1
    What is the `json_encode`/`utf8_encode` combo supposed to do? If your database were to operate with Unicode characters already, why that encoding step? – mario Feb 14 '17 at 22:50
  • I take that php variable and hand it over to a javascript variable, without the encoding, my code doesn't work. That way it works – Inkperial Feb 14 '17 at 22:53
  • The "doesn't work" part is caused by your result fetching not returning UTF-8 strings. And you know what, Latin-1 doesn't contain the Euro sign. – mario Feb 14 '17 at 22:55
  • Oh, ok... so what would be the collation to go for? Or how would it be possible to display that € anyway? – Inkperial Feb 14 '17 at 23:00
  • OK DID IT! the utf8_encode was the problem as I was setting mysql_query("SET NAMES utf8") too! Thanks for that hin! <3 – Inkperial Feb 14 '17 at 23:14

1 Answers1

1

s encoded UTF-8. You should have an option to that effect in your editor's or IDE's "Save as" dialog.

Then make sure your connection is UTF-8 encoded as well - it is ISO-8859-1 by default.

After connecting to the database, for mySQL before 5.0.7:

mysql_query("SET NAMES utf8"); For mySQL 5.0.7 and newer:

mysql_set_charset("utf8");