0

I have a website with database that works fine in my computer, all special characters displayed correctly - I made sure to save all pages and CSS in Western European format and declare charset ISO-8859-1.

Nonetheless, when I upload the project to a web server, all accented/latin/whatever-you-call-them characters, such as ~, ^, ´, etc., are replaced by question marks.

I don't know what is causing this, but I suspect it is due to my files using lots of PHP includes: 1 for heading section, 1 for footer section (since heading and footer look the same in all pages, I wanted to save some space by reusing the code).

My second hypothesis is that it has something to do with the web host. But honestly, I'm lost and have no clue what to do. If you guys could give me a solution, I'd really appreciate it.

Update: my question was marked as duplicate, BUT idk how this can be an duplicate, since I've searched this site through and through and nothing solved my problem. I did all people generally recommend: changed database collation, saved every file in ISO-8859-1 encoding, declared the correct <meta charset> in header section and it had no effect.

Educative
  • 3
  • 6
  • 1
    There is no such thing as a "special characters". There are only characters. Lots of 'em buggers. What should be "special" about "special characters" anyway? – arkascha Nov 28 '16 at 18:27
  • 2
    You have to take care that _all_ components of your setup use the same character encoding, not just some. You should generally use unicode these days (UTF-8), not an 8bit character encoding as you currently do. Start reading here: http://stackoverflow.com/questions/279170/utf-8-all-the-way-through – arkascha Nov 28 '16 at 18:29
  • special characters are: á é í ó ú ã õ â ô ê ç and the like – Educative Nov 30 '16 at 12:23
  • So tell us: what is "special" about them? Those are 11 arbitrary characters out of a uniform set of roughly 112000. That's all. – arkascha Nov 30 '16 at 12:24
  • @arkascha Man, it's just what we call them here in my country. Only thing "special" about them is that they are a big cause of headaches. And it's not arbitrary, look at the pattern: they are all accented characters (characters with ´, ^, ~, ¨, ç and such). In English, people don't use them. But in portuguese, they can be a pain in the ass. – Educative Nov 30 '16 at 13:07
  • And... idk why, they are always replaced by question marks or other strange characters when something is not right with the encoding. And, in my case, I can't find out what is wrong. – Educative Nov 30 '16 at 13:16
  • It is true that English uses an extremely small alphabet. Most other languages differ in that, even most western european languages. But still that does not make the characters themselves somehow special. Anyway, it is clear what you refer to. And that should be solved if you consequently change your environment such that all components use the same encoding, as already mentioned earlier. Did you go through the answer I referenced? – arkascha Nov 30 '16 at 13:34
  • We need more details if the duplicate doesn't help you. What kind of question mark? A question mark in a diamond? Or just plain "?"? What's the encoding-related headers you're setting? Have you tried all the steps from the duplicate? If so, list out what exactly you've done. – deceze Nov 30 '16 at 13:35
  • [Handling Unicode Front To Back In A Web App](http://kunststube.net/frontback/) – deceze Nov 30 '16 at 13:35
  • It's a diamond with a question mark. And all my files use the same file for the header - PHP include. That header is set to ISO-8859-1. Sending you guys a few prints, perharps that will help: http://prntscr.com/ddmks7, http://prntscr.com/ddmm5t, http://prntscr.com/ddmn1d, http://prntscr.com/ddmnew. @arkascha: please, set the "special" thing aside. It's just how we call it. You probably call it "lating characters" or "characters with accent", idk. It's just a name for a troublesome grammar feature. – Educative Nov 30 '16 at 13:47
  • Please forget the idea that those characters are the issue. They are not. Your setup is the issue. Stop using an 8bit encoding (ISO-8859-1), that will cause issues again and again. Use unicode encoding (UTF-8) which is the standard today and has been for many years. Use it thoughout your whole setup, as described in the answer I referenced. – arkascha Nov 30 '16 at 13:50
  • Ok, I'll try this up. – Educative Nov 30 '16 at 13:52
  • If your content is using the 8859 encoding and the ***non-ASCII characters*** (proper terminology) are showing up with a question mark in a diamond, that means the browser is actually trying to interpret the data as UTF-8. The reason for that would be that you're *not* setting the correct header, likely you're missing the proper **HTTP `Content-Type` header**. – deceze Nov 30 '16 at 13:54
  • @arkasha, thank you man! It finally worked! Here is what I did: 1 - changed the encoding to utf-8 in all files (css and js included), 2 - set the meta charset to utf-8, 3 - changed database and tables collation to utf8mb4_unicode_ci, 4 added the following code to my database connection file: mysqli_set_charset($link, 'utf8mb4'); – Educative Nov 30 '16 at 16:28
  • thanks, @deceze, that was really enlightening – Educative Nov 30 '16 at 16:29

0 Answers0