-1

I have a database which I fill directly in PhpMyAdmin. There are some special characters like é in it. In PhpMyAdmin, they show perfectly. When I convert them to PDF with FPDF/PHP they show perfectly as well. When I want to show them in HTML (with PHP), they become diamond shapes with a question mark in it.

I know this has something to do with charsets and collation, but I'm a total noob on that matter. My database has collation latin1_swedish_ci and I want to keep it that way. My page has <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> in the header, so they should be the same I think, still, I get question mark diamonds... How do I get the characters I want?

Please don't say I have to convert everything to utf-8. I really want to keep latin1_swedish_ci. I tried charset=utf-8 in the header and converting one of the fields in my database to utf8_general_ci, but that field didn't show up right either, so something else must be wrong...

Cropje
  • 67
  • 1
  • 7
  • possible duplicate of [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) – deceze Jul 15 '15 at 16:10
  • [Handling Unicode Front To Back In A Web App](http://kunststube.net/frontback/) – deceze Jul 15 '15 at 16:10
  • The above all assume Unicode/UTF-8, but just replace that with your favourite encoding. The important part is to be consistent all the way through with your encoding declarations, and declare your used encodings everywhere needed. The above resources tell you where. – deceze Jul 15 '15 at 16:12
  • Also, seeing "question marks with diamonds" indicates that your page is being interpreted as UTF-8/Unicode. That probably means your **HTTP headers** are declaring the wrong encoding, superseding your `` declaration. – deceze Jul 15 '15 at 16:13

2 Answers2

1

Thanks to the comments of deceze, I added to the top of my PHP:

<?

header('Content-Type: text/html; charset=iso-8859-1');

?>

Never knew that the meta-tag http-equiv was only a fallback!

These tags are only fallbacks though which are only used when no HTTP Content-Type header was encountered (the wording "http-equiv" hints at this). It's also conceptually weird, since these tags are inside the document itself and the browser needs to read the document first in order to figure out what kind of document it's dealing with.

Source: Handling Unicode Front To Back In A Web App

This source helped a lot! Thanks deceze!

Cropje
  • 67
  • 1
  • 7
0

Put this inside <head> tag

<meta charset="iso-8859-1">
Prasant Kumar
  • 1,008
  • 12
  • 13