Cyrillic shows fine in db, displays ? on website

I tried to switch all my content in the database to UTF8 because some characters weren’t showing up. I switched everything in the database, all column collations, tables, etc to
utf8_general_ci. I made sure my header.php specifies the charset as UTF8. I added

AddDefaultCharset UTF-8

to .htaccess. I also ran the query:

SET NAMES utf8

directly in the database. But when I try to load the page I’m getting ??? where Cyrillic should be. I can even see the correct characters in the database. Firefox displays Cyrillic just fine everywhere not on my site, so I can’t figure out what’s wrong.

Do you know the encoding of your server? You can check in your browser what encoding the server is using as it delivers pages. E.g. In Chrome, go to View > Encoding.

Looks like everything is set to UTF-8 and left-to-right. I’ve since exported the database as utf8 and then dropped everything and imported it and that didn’t work. This problem also exists in IE, Firefox, and Chrome.

Temporary workaround I’ve found while waiting to fix the issue, I converted the cyrillic into straight HTML and just put that into the db. Here’s the thing I used to save from having to look up each character. web.forret.com/tools/html.asp

Do you send this header in the beginning of your script?

header("Content-type:text/html; charset=utf-8");

And also this query should be executed each time right after connection to DB in your script (not just once):

SET NAMES utf8

Yeah, I have my header.php set to incorporate that, I’m going to try updating my db connection settings for your second suggestion.

The problem is not in your DB (you’ve covered that). To me, your problem stems from:

  • the PHP script (.php)
  • the HTML template (.html)

Make sure BOTH are also UTF-8. For example, in your editor, make sure the “File Settings” is UTF-8 also. If it’s anything other, you’re going to have problems.

Everything must be UTF-8 not just the DB. Remember, the users will be typing stuff into your HTML web forms, and in this case your web form / HTML template should also be UTF-8 as well as add accept-charset=“UTF-8” in your web :

<form ....... accept-charset="UTF-8">

What charset is the connection between PHP and MySQL set to use (and what database extension is being used)?

another thing to try when outputting to webpage:
htmlentities( $string, /ENT_QUOTES/ENT_NOQUOTES, ‘UTF-8’ )

My header has the utf8 charset in there, and I was using Notepad++ set to UFT-8 without BOM, but I can’t figure out how to set the encoding in Brackets.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.