phpdatabaseencodingutf-8character

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


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.

I tried changing it to &pound; in the database and it just outputted £

I tried a string replace:

  $row['Information'] = str_replace("£", "&pound;", $row['Information']);

Nothing seems to work, any ideas?


Solution

  • 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:

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