I have a website where I've used php to include sections rather than having code be duplicated for each page.
However, recently my webhost upgraded the PHP to 5.6, and now all my Æ, Ø and Å's give me the replacement character (�).
I'm not running any databases, and setting a charset in the html didn't help.
I'm very inexperienced with PHP, so I have no idea how to fix it.
Please, any help would be great!
Since ASCII bytes do not occur when encoding non-ASCII code points into UTF-8, UTF-8 is safe to use within most programming and document languages that interpret certain ASCII characters in a special way, such as / (slash) in filenames, \ (backslash) in escape sequences, and % in printf.
The simplest way to upgrade to PHP 7 is by asking your hosting company to update it for your account. Of course, this means you'll need to be working with a hosting company that supports PHP 7 in the first place. Some companies make it easier to upgrade to PHP 7 than others.
It is estimated that PHP 7 offers a 100 percent improvement in terms of performance, speed when compared with PHP 5.6. This major speed improvement enables web developers to design sites that render exciting and appealing interactive features that still respond to user input as quickly as web users expect it to work.
I had the same problem after upgrading from php 5.5. to 5.6.
Solved it by setting the default_charset to an empty string in my script:
ini_set("default_charset", "");
Or if you have acceess to php.ini you can set default_charset = ""
instead.
More info: https://www.saotn.org/php-56-default_charset-change-may-break-html-output/
PHP 5.6 changes the default value of default_charset
to UTF-8
.
The value should better be set.
If the charset of your php files is ISO-8859-1
(all in the directory) you can easy put a .htaccess File in the root directory:
php_value default_charset ISO-8859-1
If only some of your files are in ISO-8859-1 you can easy send a header in the first line of the php file (no need for default_charset):
<?php
header('Content-Type: text/html; charset=iso-8859-1');
?>
Or convert the encoding of php textfiles to utf8 and don't change defaults.
For now the best thing to do is to downgrade to PHP 5.5 or 5.4, because of what CBroe explained in his commentary saying that PHP 5.6 now sets default charset as UTF-8 and many websites are still not ready for it. I had the same issue after migrating to a new server, so I downgraded to PHP 5.5 and automatically all the special characters are displaying correctly again. If you're using WHM, use EasyApache to rebuild Apache and then select the desired PHP version when prompted.
I personally think that PHP developers should warn users better, I mean, making it clear that upgrading to version 5.6 can bring special characters issues for non UTF-8 ready websites/applications. What they did just imposing UTF-8 to millions of developers worldwide was too fast or even too radical.
If you have multi host web server especially with older websites and multiple languages, for maximum compatibility with earlier PHP versions like 5.4 just force reset default_charset value in /etc/php.../php.ini:
In the global [PHP] section find this key and edit, or put like this:
default_charset = ""
This will not force PHP to set UTF-8 charset for all php files, especially older legacy or national encoding like windows-1251
, windows-1257
, iso-8859-1
, iso-8859-2
, ISO-8859-13
and similar.
Or if you are developer, sure use Rob's answer and add code directly to you php application ini_set("default_charset", "");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With