4

My hosting service recently upgraded my website server from PHP 5.3 to 5.6 and it broke my site in that all my html/php files are ISO-8859-1 but the site is now being served up with response headers indicating

charset=UTF-8

I understand I should move to UTF-8 files eventually but in the meantime I want a quick-fix. I've tried the following fixes:

<meta charset="ISO-8859-1"> (in the <head> tag of html files)

AddDefaultCharset ISO-8859-1 (in .htaccess)

default_charset= "ISO-8859-1" (in php.ini)

...but none of these affected the response header charset.

The only thing that worked in testing was adding this line to my header.php file used by most (not all) of my pages:

header('Content-Type: charset=ISO-8859-1');

But I don't want to hunt through all the straggler files and add that to each. I might as well convert all the files to UTF-8 if I'm going to hunt them and touch them in that way.

So...I was wondering if anyone would know why my PHP.ini or htaccess fixes don't do the job universally? Does the fact that these are not working indicate that some other Apache setting is in control of the response header for charset?

Thanks in advance.

Update: I even tried adding

addCharset ISO-8859-1 .html .htm .php 

to .htaccess but no joy.

Avimelech
  • 41
  • 1
  • 1
  • 4

5 Answers5

8

Spiele-Umsonst's answer didn't work for me (on Apache), but this did the trick:

php_value default_charset Off
AddDefaultCharset ISO-8859-1

"Off" is a valid value for "AddDefaultCharset", so I guess for default_charset as well. "None" is not valid, so I guess that's why it didn't work. I think this might depend on some server configurations or the http deamon used.

Further reading for Apache web server: http://httpd.apache.org/docs/current/mod/core.html#adddefaultcharset

4

This in .htaccess will help you my friend:

php_value default_charset None
AddDefaultCharset ISO-8859-1

And don't forget the html-files :P Clean them from the meta tag or make sure they are alos ISO

2

If the above doesn't work, you may want to try something like this at the top of your PHP file:

mb_internal_encoding("iso-8859-1");
mb_http_output( "iso-8859-1" );
ob_start("mb_output_handler");
DesignConsult
  • 191
  • 1
  • 4
0

For Apache, the default charset is set in httpd.conf. Check out this thread: Setting PHP default encoding to utf-8?.

Good luck!

Community
  • 1
  • 1
Stijn Hooft
  • 170
  • 1
  • 12
  • There is no access to that on my host (Pair.com) It's very weird, PhpInfo() says the default_charset = ISO-8859-1 now, but the content-type header still comes out as charset=UTF-8. – Avimelech May 18 '15 at 02:25
0
  • php_value changes php config
  • AddDefaultCharset changes apache config

To make modifications in .htaccess or /etc/apache2/sites-available/? That depends of the scope needed.
I wrote in .htaccess php_value default_charset ISO-8859-1 to override the value of php.ini default_charset UTF-8.
It is running because I haven't an AddDefaultCharset in my apache config file. I add in .htaccess AddDefaultCharset ISO-8859-1 to prevent.

Pascal KOCH
  • 109
  • 1
  • 2