Override Webserver Page Encoding?

I have pages that I manually encoded in PHP over 10 years ago.

They are encoded in the old Hebrew encoding - windows-1255

Recently, they were all broken - the text is displayed as unrecognized UTF-8 characters - a diamond with a question mark inside.

When I manually change the encoding in the browser - any browser - the text is displayed correctly.

I thought that maybe the server on my host is forcing UFT-8 encoding. I have a .htaccess change to force windows-1255 encoding, but that didn't work.

I tried to check the page through W3C and it sees the page as UTF-8

I downloaded XAMPP and started the server locally and it still happens.

Has anything changed over the past year in the way Apache serves web pages regarding coding?

Before going to all my pages and changing their encoding, I would like to know if there is a global “switch” that I can flip so that my pages display correctly.

Thank.

+4
source share
1 answer

After long attempts, the good-natured soul helped me understand that this is not Apache, redefining the encoding in the header, but PHP itself.

Adding

header('Content-Type: text/html; charset=windows-1255');

At the top of the PHP file, the problem is fixed.

As far as I understand, the chain is this:

  • By default, Apache sends content to the UTF-8 header.
  • If another encoding is set to .htaccess, the browser accepts it.
  • PHP , _charset php.ini

, , , .

+2

Source: https://habr.com/ru/post/1665827/


All Articles