Some characters become “�” in our webpage

前端 未结 3 515
挽巷
挽巷 2021-01-23 19:02

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 st

相关标签:
3条回答
  • 2021-01-23 19:37
    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.

    0 讨论(0)
  • 2021-01-23 19:40

    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>
    
    0 讨论(0)
  • 2021-01-23 19:45

    Make sure that you use:

    <meta charset="utf-8"> 
    

    in the head of your page.

    0 讨论(0)
提交回复
热议问题