doumo3903 2015-11-09 08:52
浏览 24
已采纳

在php中显示字符编码

I have retrieve data from MySQL in php and post it to client: if I use select * from users LIMIT 8; no problem.. but when 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:

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:

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��???' 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?

EDITED: since I see in 'Öney' character in script variable I think in php page there is problem..

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");
  • 写回答

2条回答 默认 最新

  • duanbamo0127 2015-11-09 08:56
    关注

    You're specifying the charset as UTF-8 in meta:

    <meta charset="utf-8"/>
    

    But you're specifying ISO-8859-1 in PHP:

    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:

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

    Other steps that might help:

    1. Setting the file encoding to UTF-8.

    2. Setting the table columns to be in UTF-8 (utf8-general usually works).

    3. Running the query SET NAMES utf8 after connecting to the database.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么