Encoding problem: ยฃ pound symbol denoted as <?> Symbol

My database field is set to utf8_general_ci, and the encoding of my sites is set to utf8.

The ยฃ symbol appears as a black diamond with a question mark across the center.

I tried changing it to &pound; in the database, and he just pulled & pound;

I tried replacing the string:

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

Nothing works, any ideas?

+2
source share
2 answers

I tried changing it to &pound; in the database

not to do. The database should contain the source text, not HTML-encoded content. The time for HTML coding (using htmlspecialchars() ) is when you paste some raw text into HTML at the output template stage, and not earlier. Even if you have it at work, you would only set one character; the remaining 107025 characters other than ASCII will still be broken.

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

  • the encoding into which you saved the PHP file, if it contains any characters other than ASCII;
  • the encoding declared on the output page (by Content-Type <meta> or header() , both are desirable; if you use only <meta> to install it and the server is configured incorrectly, it can set its own charset redefinition of your );
  • column encoding in the database (each column has its own sorting, so just setting it on the table is inefficient);
  • The encoding used by PHP to communicate with MySQL. This needs to be set using mysql_set_charset .

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

+4
source

Before communicating with your database you need to send a request:

 SET NAMES 'UTF-8' 

It tells the database to use utf8 encoding for all requests in this connection.

+1
source

Source: https://habr.com/ru/post/1402566/


All Articles