Some characters become “�” in our webpage

2020-04-19 07:01发布

I use PHP to access a database to get a string like this

‘Chloe’ Fashion Show & Dinner

and then I do a printf() to output the string as html, but my webpage shows this:

�Chloe� Fashion Show & Dinner

All contents are English-based, do I miss something in PHP?

Where should I be checking?

3条回答
你好瞎i
2楼-- · 2020-04-19 07:11

You need to add charset meta tag in 'head' section of html. Note that the meta tag must appear within the first 1024 bytes of rendered page.

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
查看更多
Root(大扎)
3楼-- · 2020-04-19 07:18
  1. Check if your .php file is encoded as UTF-8 without BOM
  2. Check that your connection to the database is UTF-8
  3. Check that you send <meta charset="utf-8"> in your HTML markup in the <head> tag

If your connection to the database is not UTF-8 and you don't want to change it (but I recommend it -> everything UTF-8 is the most secure solution against character rubbish) use utf8_encode($databaseValue) to ensure the encoding of your value is UTF-8.

查看更多
乱世女痞
4楼-- · 2020-04-19 07:23

Make sure that you use:

<meta charset="utf-8"> 

in the head of your page.

查看更多
登录 后发表回答