简体   繁体   English

在php中显示字符编码

[英]display character encoding in php

I have retrieve data from MySQL in php and post it to client: if I use select * from users LIMIT 8; 我已经在PHP中从MySQL检索数据并将其发布到客户端:如果我使用select * from users LIMIT 8; no problem.. but when select * from users LIMIT 9; 没问题..但是当select * from users LIMIT 9;select * from users LIMIT 9; the last data retrieved broke the page.. when I debug in php I can see this data looks fine also: 最后检索到的数据打破了页面..当我在php中调试时,我也看到此数据看起来还不错:

1 = "CN=User1,OU=ARGE,OU=Personel,OU=Kullanicilar,OU=CompanyName,DC=company,DC=intra 2 ="CN=User2,OU=ARGE,OU=Personel,OU=Kullanicilar,OU=CompanyName,DC=company,DC=intra 3 ="CN=User3,OU=ARGE,OU=Personel,OU=Kullanicilar,OU=CompanyName,DC=company,DC=intra 4 ="CN=User4,OU=ARGE,OU=Personel,OU=Kullanicilar,OU=CompanyName,DC=company,DC=intra 5 ="CN=Öney,OU=ARGE,OU=Personel,OU=Kullanicilar,OU=CompanyName,DC=company,DC=intra

But there is no data returned from php.. its obvious that 'Ö' character cause this but I don't understand why its even looks true and my character encoding is: 但是没有从php返回的数据。.很明显,'Ö'字符引起了这种情况,但是我不明白为什么它看起来很真实,而我的字符编码是:

My PageÖÖ 我的页面

and this is also in top of my page : 这也是我页面的顶部:

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

When I type a title '4 Tasks to completeÖÖŞŞŞ' in html of mypage.php it looks: '4 Tasks to complete ???' 当我在mypage.php的html中键入标题``完成4个任务''时,它看起来是:``完成4个任务''。 In stackoverflow it looks well, I want same for mine.. couldn't figure out the problem now in html or php or both of them? 在stackoverflow中看起来不错,我想要我的..现在在html或php或两者中都找不到问题了吗?

EDITED: since I see in 'Öney' character in script variable I think in php page there is problem.. 编辑:由于我在脚本变量中看到“Öney”字符,所以我认为在php页面中存在问题。

my connection settings: 我的连接设置:

$this->dbh = new PDO('mysql:host=localhost;dbname=webfilter;port=3306;connect_timeout=15', 'root', 'company');
            $this->dbh->exec("set names utf8");

You're specifying the charset as UTF-8 in meta: 您要在meta中将字符集指定为UTF-8

<meta charset="utf-8"/>

But you're specifying ISO-8859-1 in PHP: 但是您要在PHP中指定ISO-8859-1

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

You'll need to have consistency, change the PHP header function to set the charset as UTF-8 too: 您将需要保持一致性,更改PHP标头函数以将字符集也设置为UTF-8:

header('Content-Type: text/html; charset=utf-8');

Other steps that might help: 其他可能有帮助的步骤:

  1. Setting the file encoding to UTF-8. 将文件编码设置为UTF-8。

  2. Setting the table columns to be in UTF-8 (utf8-general usually works). 将表列设置为UTF-8(通常使用utf8-general)。

  3. Running the query SET NAMES utf8 after connecting to the database. 连接到数据库后,运行查询SET NAMES utf8

Change 更改

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

to

header('Content-Type: text/html; charset=utf-8');  

In HTML, charset is utf-8 , but it is different in PHP. 在HTML中, charsetutf-8 ,但在PHP中则不同。 Make sure that they are same. 确保它们相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM