1

I have a site under construction where user posts are displayed. In the development server(on Windows XP) using PHP 5.2.5 and Apache 2.2.6 it is fine,i.e.,special characters are displayed as it is by adding the charset meta tag into the header section of the html page:

<meta charset="utf-8">

And echoing like this:

echo html_entity_decode($postBody, ENT_QUOTES, 'UTF-8');

Then,for example,results are as follows:

███─█─────█─███─███─███ █───█─────█─█───█────█ ███─█──█──█─██──██───█ ──█─█─█─█─█─█───█────█ ███─██───██─███─███──█

███─███──███─███─██───█─███─ █───█─█───█──█───█─█──█─█──█ ███─██────█──██──█──█─█─█──█ █───█─█───█──█───█───██─█──█ █───█──█─███─███─█────█─███─

Currently,I have uploaded my project into a new development server (on Windows7) with PHP 5.6.29 and Apache 2.4.23 where the same page is displayed as below:

███─█─────█─███─███─███ █───█─────█─█───█────█ ███─█──█──█─██──██───█ ──█─█─█─█─█─█───█────█ ███─██───██─███─███──█

███─███──███─███─██───█─███─ █───█─█───█──█───█─█──█─█──█ ███─██────█──██──█──█─█─█──█ █───█─█───█──█───█───██─█──█ █───█──█─███─███─█────█─███─

In the new environment, I have also tried with:

echo utf8_encode($postBody);

But it was fruitless. I also added in the httpd.conf:

AddDefaultCharset utf-8

The default_charset in PHP has been checked and also found to be utf-8.

But it was all in vein.

I have also checked the character_set_database in MySQL in both the servers(previous and new) which is found to be latin1.

I am pointless as why the same page displayed differently in two versions despite trying myself this little bit. What are the possibilities that lead me to such problems and how will I come out of it with a solution? Thanks in advance!

Parveez Ahmed
  • 1,325
  • 4
  • 17
  • 28
  • Look for "Mojibake" in http://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored – Rick James Jan 08 '17 at 18:52

1 Answers1

0

The default charset for PHP was changed to UTF-8 in Php 5.6. See this link: PHP 5.6 default_charset change may break HTML output.

It means the default charset for functions that require charset as an argument is UTF-8 by default since PHP 5.6. Also PHP sends a content-type header with value UTF-8.

That is probably why your code does not display the same output after you switched to PHP 5.6

If the data your are trying to display is being fetched from MySQL database, then you should change the charset of the MySQL table and database to UTF-8. After that try to reenter the data to the database so it stored with the UTF-8 character encoding.

See also: Php Ini Directives

Nadir Latif
  • 3,690
  • 1
  • 15
  • 24
  • Thank you, I have yet to try this with your answer. But for the moment, I have set charset in the page instead of content-type header. Don't they do the same thing for me ? – Parveez Ahmed Jan 11 '17 at 16:10
  • Well the content-type header is a http header that the web server sends to the browser. Php >=5.6 automatically sends this header. Both the content-type http header and the charset meta tag do the same thing, so you dont need to add the meta charset tag to the page – Nadir Latif Jan 12 '17 at 03:27