简体   繁体   中英

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; 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");

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.

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. Make sure that they are same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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