1

In some pages of my site, the character-encoding appears clean and in some other pages it is not good.

For example, it could appears like this : Flu¨e, instead of this : Flüe.

I am working on Wordpress, with my own theme. My php document is set on <meta charset="<?php bloginfo( 'charset' ); ?>">. I have also tried with <meta charset="UTF-8"> but it doesn't solve the problem.

Here is the head of my header.php file :

<head>

  <meta charset="<?php bloginfo( 'charset' ); ?>">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="Temporary Gallery, Centre for contemporary art, Köln" />
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <link rel="stylesheet" href="dist/css/bootstrap-responsive-tabs.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<head>
Rathan Naik
  • 993
  • 12
  • 25
Lolo
  • 125
  • 2
  • 16

1 Answers1

0

Try to figure out what the strings that are being displayed badly have in common - as in what is their common source - they are coming from a different text files/databases/tables - that should give you some hints where is the source of the problem. PHP does not convert any text automatically so look at where it is originally located.

If you can pinpoint more exactly where the text start appearing garbled then we can help you better.

Some things you can investigate based on my personal experience with these types of problems:

First off ensure your .php document (the file itself) is of a correct encoding. You should be able to set it in your text editor or IDE. This can happen if you have copied over files from different places. If you have files not encoded in UTF-8 then convert them.

Secondly ensure that the data that you fetch into that file is being fetched using UTF-8 encoding. You may for example have some code that fetches data from a database where different tables have different encoding, or the text is being cast in different encoding, check this for more info: https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html (let us know if you are using a different database like Postgres). You can try printing the string coming from a database right after it is returned - if it is fine but it is displayed badly on the page then obviously some bad formatting is being done afterwards and the database is fine.

Thirdly the text saved into your properly set up to utf-8 tables might get saved in a wrong encoding - you might need to correct it directly or check the code that does the saving into the database.

The database server also might be configured to serve results in a different encoding and you might need to set it up properly: Change MySQL default character set to UTF-8 in my.cnf?

Another option is for you to look for any functions that deal with conversion of encodings like http://php.net/manual/en/function.utf8-encode.php - it may be that something like that is happening unnecessarily and it is being done for a text that is already in utf-8, or is in a different encoding and you need another function.

Radix Salvilines
  • 386
  • 5
  • 16
  • thank you for this detailed explanation! I think my files are setted correctly, because the text formatting is good, except with the "u" lower case in conjunction with the ¨. So, every " ü " appear like " u¨ ", only for lower case. Upper case text and other letters work fine… – Lolo Sep 08 '17 at 10:21
  • are your ü's written directly in your document or are you fetching them from a different source? Can you print it to your log with the use of error_log(print_r($faulty_string, 1)); and see if it is okay in your error log? – Radix Salvilines Sep 08 '17 at 10:28
  • Actually, my ü's are written directly in my Wordpress posts admin. But I realized that they appear good in the admin and not good in the site. They are from copied and pasted texts… – Lolo Sep 08 '17 at 10:41
  • Look here: https://developer.wordpress.org/reference/functions/get_post/ try to print before the return $_post; how the string looks like maybe - is it sill fine? – Radix Salvilines Sep 08 '17 at 10:46