Encoding issue: £ pound symbol appearing as <?> symbol

前端 未结 2 1593
感情败类
感情败类 2021-01-22 02:02

My database field is set to utf8_general_ci and my websites encoding is utf8.

The £ symbol is coming up as a black diamond with a question mark through the center.

相关标签:
2条回答
  • 2021-01-22 02:55

    Before communicating with your database, you need to send the query :

    SET NAMES 'UTF-8'
    

    It tells the database to use utf8 encoding for all queries on this connection.

    0 讨论(0)
  • 2021-01-22 02:59

    I tried changing it to &pound; in the database

    Don't. The database should contain raw text, never HTML-encoded content. The time to HTML-encode (using htmlspecialchars()) is when you insert some raw text into HTML at the output templating stage, and not before. Even if you got this to work, you'd only have fixed one character; the other 107025 non-ASCII characters would still break.

    Clearly there is a mismatch of encodings here; you must ensure you use the same encoding (preferably UTF-8) everywhere, in particular:

    • the encoding you've saved the PHP file in, if it contains any non-ASCII characters;
    • the charset declared on the output page (by Content-Type <meta> or header(), preferably both; if you only use a <meta> to set it and the server is incorrectly configured it may set its own charset overriding yours);
    • the encoding of the column in the database (each column has its own collation, so just setting it on the table is ineffective);
    • the encoding used by PHP to talk to MySQL. This should be set using mysql_set_charset.

    Unfortunately, none of these settings default to UTF-8.

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