0

1) I migrated WEB page to another server! From Ms Server 2012/Xampp to Cento7/httpd. On Centos7 Web page contains question marks where should be a special characters "āīūņļš". Web page is built on PHP.

Old server is running old XAMP installation:

  • PHP Version 5.4.27
  • 5.5.36 - MySQL

CentOS running:

  • apach/httpd
  • PHP 7.0.*
  • 5.5.52-MariaDB

2) Both servers contains files with same encoding and DB tables with same charset colletions and both servers have "Server charset is UTF-8 Unicode (utf8)".

Only difference is "Server connection collation". Old server have "Collation" and CentOS have "utf8_general_ci".

3) I tried:

  • encode files to utf8
  • define utf8 in meta tags
  • header('Content-Type: text/html; charset=ISO-8859-1'); and header('Content-Type: text/html; charset=utf8');
  • mysqli_set_charset($con,"utf8");
  • AddDefaultCharset UTF-8 in httpd.conf

I just don't understand, why on one server everything is OK and on another server text contains "?" when files/php code/db is the same! Is there a chance that the httpd doesn't have some module enabled?

And there is one more problem! Some php files and DB tables have different encoding and char collection. I tried change file encoding to UTF8 and it solved problem for static text in php files. Some text in db contains strange characters and db contains lot of information. In some cases mysqli_set_charset($con,"utf8"); works but there ar times when text randomly disappear when mysqli_set_charset is used!

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Does the text originate from the database or from PHP files? If they are from the database, do they look correct in the database itself? You can check this with an application like [PHPMyAdmin](https://www.phpmyadmin.net). – KIKO Software Sep 25 '17 at 11:43
  • Might be worth going through this: https://stackoverflow.com/questions/279170/utf-8-all-the-way-through/279279 ... plus `header('Content-Type: text/html; charset=utf8')` in the HTTP header `utf8` should be hyphenated, `utf-8`, though I'm not sure how antsy that is (never tried it without the hyphen). – CD001 Sep 25 '17 at 11:47
  • 1) Text originate from DB and PHP file. Static Text from PHP files looks fine when UTF8 encoding is used for files! 2) Yes problem is that text in DB contains some strange symbols! But old server DB also contains text with strange symbols and in web page text somehow is ok! – Ķirbis Cool Sep 25 '17 at 11:55
  • With this i want to say that, the text in the old server database contains strange symbols, but the text is displayed correctly by pulling out the information in the web page from the old server database. When the information is pulled from a new server, the text in web page contains "?". Right know both servers is 1:1 (files and file encode / db and collection). The database contains too many entries to manually overwrite it! – Ķirbis Cool Sep 25 '17 at 12:14
  • Oh - you've got garbage data in the database itself then (e.g. UTF8 characters that have been converted to ISO-8859-1)... I've run into that a couple of times with old/badly written CMS systems. Seem to remember I wrote a MySQL UDF to clean it up in the end. – CD001 Sep 25 '17 at 15:42
  • Not enough info. Give us an example of text the turned into `?`. It may be something that needs `utf8mb4`. Otherwise, see "question mark" in http://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored for debugging your specific problem. – Rick James Sep 25 '17 at 20:39
  • As I said, the difference was the "collation_connection". My cousin suggested, to check "collation_connection", and then export tables with corresponding charset! Then check if the characters are saved correctly! If characters ar saved correctly in sql file, convert sql files with utf8. Now i have sql files with correct text and i need just prepare db/tables with "UTF8mb4_general_ci". I checked the defloult "collation_connection" with HeidiSQL and it was "ISO-8895-1". Thanks for the help! – Ķirbis Cool Sep 26 '17 at 08:00

0 Answers0