UTF-8 works on hosting A but not on hosting B, wha

2019-07-23 07:21发布

I have hosting plans with 2 different providers, on provider A my website work without a single issue but on provider B no matter what I do the UTF-8 never works.

The website in both hosting are exact the same in every aspect so the only difference we have here is the server.

If I simple create a file with the below content on notepad saving as UTF-8 enc:

<?php
header('content-type: text/html; charset: utf-8'); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?
    $var = "áéíóí";
    echo $var;
?>
<body>
<html> 

It works fine on hosting A but fails to show the characters on hosting B.

I have checked both php.ini files and both have the same information.

What else could I try, change or attempt to get UTF-8 working on hosting B ?

From what I can tell it seems entirelly server side issue some configuration missing or so otherwise why the same site would work on hosting A without demonstrating a single issue ?

CURL response hosting B:

root@server:~# curl -v http://painel.xxxxxx.com/test.php
* About to connect() to painel.xxxxxx.com port 80 (#0)
*   Trying 10.0.0.2... connected
* Connected to painel.xxxxxx.com (10.0.0.2) port 80 (#0)
> GET /test.php HTTP/1.1
> User-Agent: curl/7.20.1 (i686-pc-linux-gnu) libcurl/7.20.1 OpenSSL/0.9.8n zlib/1.2.5 libidn/1.5
> Host: painel.xxxxxx.com
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Thu, 15 Sep 2011 11:55:33 GMT
< Server: Apache/2.2.15 (Unix) mod_ssl/2.2.15 OpenSSL/0.9.8n DAV/2 mod_python/3.3.1 Python/2.6.4 PHP/5.3.6 SVN/1.6.11 mod_fastcgi/2.4.6
< X-Powered-By: PHP/5.3.6
< Transfer-Encoding: chunked
< Content-Type: text/html; charset=utf-8
<
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
áéíóíaed<body>
* Connection #0 to host painel.xxxxxx.com left intact
* Closing connection #0
<html>

FireBug response hosting B from my computer:

HTTP/1.1 200 OK
Date: Thu, 15 Sep 2011 12:06:21 GMT
Server: Apache/2.2.15 (Unix) mod_ssl/2.2.15 OpenSSL/0.9.8n DAV/2 mod_python/3.3.1 Python/2.6.4 PHP/5.3.6 SVN/1.6.11 mod_fastcgi/2.4.6
X-Powered-By: PHP/5.3.6
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8

Host    painel.xxxxxxx.com
User-Agent  Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language pt-br,pt;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding gzip, deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection  keep-alive
Cookie  
Cache-Control   max-age=0

Tried so far:

  • changed hte locale from the OS to en_US.UTF8
  • changed the default charset on apache
  • set the charest to utf-8 on php.ini
  • files are save on UTF8
  • the same file is tested on both hosting plans and only works at hosting A.
  • at the first line of the code mb_internal_encoding("UTF-8");
  • at the first line of the code setlocale(LC_CTYPE, 'C');
  • the 2 above together
  • header('content-type: text/html; charset: utf-8'); and header('content-type: text/html; charset=utf-8');

标签: php utf-8
2条回答
forever°为你锁心
2楼-- · 2019-07-23 07:48

It should read:

header('content-type: text/html; charset=utf-8');

Plus, for your case only two things are relevant -- the Content-type header (if it's missing the corresponding meta tag) and the actual encoding used in the entity. Forget everything else.

查看更多
Animai°情兽
3楼-- · 2019-07-23 07:48

Adding the follow line to the php.ini file and rebooting the httpd service did the trick:

mbstring.internal_encoding=utf-8
查看更多
登录 后发表回答