Showing � instead of £

the symbol � is showing instead of £ when pulling data from the mysql database

the field in question its collated to utf8_general_ci

I also have the <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> on the head tag of the page

Any ideas please?


Use mysql_query("SET NAMES 'UTF8'"); before you perform any queries to the database.

As others said you should SET NAMES 'UTF8' id it not the default charset. It is also possible that the wrong characters were inserted into the database.

Check the source if it is indeed in UTF-8 format, and was imported as UTF-8. (You can re-import the data after setting NAMES with the query above).

If they were entered thru an HTML form, check if the HTML page containing your data entry form has the correct meta elemnent too.

Also check the headers your HTTP server sends you (you can do this with the Firebug extension). You can set the default charset for your server in a .htaccess file containing:

AddDefaultCharset UTF-8

If you're using PHP, the recommended way to set the character encoding is mysql_set_charset( ).

My initial setup for MySQL is:

$db = mysql_connect( ... );
mysql_set_charset( 'utf8', $db );

header('Content-Type: text/html; charset=UTF-8');
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

This way, I'm never ever having problems with encoding.

Please read

The short version: In MySQL string fields have a character set attached, and so have connections. The connection character set is the server-side representation of the client character set, it is what the server thinks the client is using.

The short way to set the connection character set is SET NAMES utf8, as mentioned in the comment above.

If the field character set is different from the connection character set, MySQL will try to convert the field to the connection character set. It will not try to do that if both are equal.

The way to debug that is, as shown in the article, to look at the field using the HEX() function, checking what the actual on-disk data is and if it is correct.

Then you connect to the database, having set your connection to the proper client character set with SET NAMES utf8, if you actually are working with utf8 as you claim. Then output the HEX() of the string again, it should be the same. If it is not, the connection does not have the right character set, for example, if you forgot to SET NAMES utf8.

You can configure the default connection character set in MySQL, using the definition of SET NAMES from the manual,

SET character_set_client = utf8;
SET character_set_results = utf8;
SET character_set_connection = utf8;

If you put this into the mysqld section of your my.cnf and restart the server, the SET NAMES should no longer be necessary, as the connection now by default will have utf8.

this also happens if you get text with jquery and ajax, try echoing the string with utf8_encode($string)

Need Your Help

java toString for any object

java reflection

I have a lot of data objects, and I want to be able to generate a String representing each object, without implementing a toString method for each one.

How to hide the horizontal Scrollbar of a ListView in JavaFX

listview javafx tableview scrollbar hide

How can I hide the horizontal scrollbar of a ListView? I tried it in different ways and probably it's totally easy, but I just can't get it to run.