Thursday, December 6, 2018

php - Page detected as UTF-8 by browsers when it has 'ISO-8859-1' as meta charset




I'm dealing with a site transfer, and in the process my charset got fouled up. At first, I transferred all files with no alterations, and the files on the new server showed icons for special characters. A glance at the browser's character encoding (Chrome and FF) told me it was auto-detecting UTF-8. The meta charset of pages is set to ISO-8859-1. Copy is drawn from various tables in multiple databases (don't ask).



On the original site, all displayed as it should. On the new site, ... I dug into it, found default charset ="UTF-8" in php.ini, set it to nothing. Now the majority of pages on the site display fine, the browser recognizes the meta charset tag, everybody's happy; that is, until I navigate to a folder off root.



The files in this folder, although their meta charset is ISO-8859-1, are somehow telling the browser to be read as UTF-8, which means I'm seeing on these pages. If I set the browser to read as ISO-8859-1, then it displays fine. Auto-detect resets it to UTF-8. Any ideas?



Thank you!



Update (added from comment below):




I ran the page through the W3C checker as recommended by martinstoeckli, and it tells me that the HTTP Content-Type is Content-Type: text/html; charset=utf-8 while the meta tag is , which gives me a Conflicting character encoding declarations error. Crazy thing is, I can't for the life of me figure out where the UTF-8 declaration is coming from! It's nowhere in any file, all files were saved UTF-8 w/out BOM, the php.ini is set to declare no default, the folder's .htaccess is set like PatomaS suggests.



(For what it's worth, Mozilla's Web Sniffer confirms HTTP header Content-Type of text/html; charset=utf-8.)



Update:
While we did not reach a solution to this problem as I posed it, I did decide that the best way to resolve my character encoding issues is to refactor everything to use UTF-8 encoding. Of course, this probably means you will see me on here with more exciting newbie questions like "Just why won't utf8-encode() do my łâùñdrÿ?"



Of course, that means the mystery remains: what is causing the server to send HTTP Content-type charset headers of UTF-8 when it appears that everything is configured differently?


Answer




Are files may have BOM (Byte Order Mark) in them. To ensure open a file with notepad++ and check Coding menu , also you can select convert to ansi as an option for a test.



BTW using utf-8 everywhere is a better -long term- approach that i can suggest.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...