Pound symbol does not appear on web page

I have a mysql database table to store the country name and currency symbol - CHARSET installed UTF8 correctly.

This is an example of data inserted into a table.

insert into country (country_name, currency_name, currency_code, currency_symbol) values 
('UK', 'Pounds', 'GBP', '£');

When I look in the database, the pound symbol seems fine, but when I extract it from the database and display it on the website, a strange square symbol appears with a question mark inside instead of the pound symbol.

Edit In my.cnf - the character set was set to latin1 - I changed it to utf8 - then I logged in as root and ran \ s - it returned

Server characterset: utf8
Client characterset: utf8

Sort Options

- Database
SELECT default_collation_name
  FROM information_schema.schemata
 WHERE schema_name = 'swipe_prod';

THIS DOES NOT RETURN ANYTHING

- Table
SELECT table_collation
  FROM information_schema.tables
 WHERE TABLE_NAME = 'country';

THIS RETURNS utf8_general_ci

- Columns
SELECT collation_name
  FROM information_schema.columns
 WHERE TABLE_NAME = 'country';

THIS RETURNS 7 ROWS but all have either null or utf8_general_ci

PHP code

<? php
$ con = mysql_connect ("localhost", "user", "123456");
mysql_select_db ("swipe_db", $ con);
$ result = mysql_query ("SELECT * FROM country where country_name = 'UK'");
while ($ row = mysql_fetch_array ($ result))
{
  echo $ row ['country_name']. "". $ row ['currency_symbol'];
}
mysql_close ($ con);
?>

Please advise thanks

+3
7

" ", REPLACEMENT CHARACTER, , 80-FF (128-255), UTF-8.

UTF-8, , ISO-8859-1.

UTF-8 ISO-8859-1 ( Firefox ViewCharacter EncodingWestern (ISO-8859-1)), .

, ? - , . , , . CHARSET UTF8, , . , . ​​charsets, .

, .

, , .

SELECT hex( currency_symbol )
  FROM country
 WHERE country_name = 'UK'

A3, , ISO-8859-1. , .

C2A3, , UTF-8. , .

EDIT 2

-- Database
SELECT default_collation_name
  FROM information_schema.schemata
 WHERE schema_name = 'your_db_name';

-- Table
SELECT table_collation
  FROM information_schema.tables
 WHERE TABLE_NAME = 'country';

-- Columns
SELECT collation_name
  FROM information_schema.columns
 WHERE TABLE_NAME = 'country';
+7

2 . utf8_encode() . , , .

+3

&pound;

£, , £, :

<%=replace(stringWithPoundInIt,"£","&pound;"%>
+1

. (PHP):

mysql_query("SET NAMES utf8");

, .

+1

mb_convert_encoding.

...

echo $row['country_name'] . " " . mb_convert_encoding($row['currency_symbol'], "UTF-8");

+1

. , , , , - .

0

, , PHP SELECT MySQL.

mysql_query("SET character_set_results=utf8", $link);
0

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


All Articles