简体   繁体   中英

Issue with PHP and UTF-8 Characters

I've been working on a website recently (localhost environment). Today I made it online and I encountred a really wierd problem :

When ever I try to output UTF-8 characters (hebrew) from my database it works perfectly, but when I try to echo simple text (ex: echo "שלום";) I get question marks (not the ones with the black background).

I've tried to search for a solution but found none. I hope you guys can help me with this

Things to check:

  1. Did you try telling the client browser what character set you're using: <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> ( <meta charset="utf-8"> vs <meta http-equiv="Content-Type"> )

  2. Is your file/editor set for UTF-8? Eclipse defaults to cp1252, common windows editors will default to ISO-8859-1 or UCS-2.

  3. In your php.ini file, confirm default_charset = "UTF-8" (see http://www.php.net/manual/en/ini.core.php#ini.default-charset )

  4. Force the content type in the HTTP transaction (via response header): header('Content-type: text/html; charset=utf-8'); Be sure to include this before any content is flushed to the browser.

Your encoding is wrong in your code files. Your editor saved them wrong, and you probably did not bother to also send a HTTP header for "Content-type", and your localhost also did not, but your online server now does.

Change the encoding, and all will be well.

I had this problem recently. Use this code to solve it:

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">

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