0

So this has been an on going issue for me. It's an area I don't understand and is really infuriating me.

I have a need to save symbols to a database on one system, then retrieve them and display them on another system.

For example, on the administration system, I have form which allows users to enter a pound £ symbol, but when I output it on one website, it displays � while on another site it displays £ correctly.

I've google, and searched stackoverflow, and this is what I've done:

  1. Set the database table to utf8_general_ci
  2. Set the field to utf8_general_ci
  3. In codeigniter, set the charset to UTF-8
  4. On the web page which is saving to the database, I have the following: <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> which results in the weird character
  5. The pound symbol in the database is successfully a pound symbol.
  6. The pound symbol on one website is displayed successfully, with the <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> tag in the head
  7. On another website, with the same tag as point 6, it's displaying the weird character still.
  8. I've added this header to PHP: header("Content-Type: text/html; charset=utf-8"); and it's codeigniter equivalent.
  9. In the web page displaying the weird characters instead of the £ symbol, the response is: Content-Type:text/html; charset=utf-8

I don't know what else to do. I've googled, and searched on stackoverflow. All posts say to use the

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

tag, which I have done on each of the site, and non of them are working.

I have also included the

<meta charset="utf-8">

tag which doesn't work.

Please help, I'm at my wits end at trying to understand why it's not working, and nothing that's been suggested is working. If you need any further information, please let me know.

Some resources I've looked at:

Community
  • 1
  • 1
Phil Cross
  • 9,017
  • 12
  • 50
  • 84

2 Answers2

0

You don't explain which systems you are using. Are you trying to get this data from a field in a table then output it in HTML?

In HTML the £ symbol is &#x000A3;

If in the database field that is stored as £ you could use

$symbol = str_ireplace("£", "&#x000A3;", $symbol);

In HTML I use the following declaration :

<!doctype html>
<html>
<head>
<meta charset="utf-8">

In this declaration &pound; and £ will also display the £ symbol.

Nullbreaker
  • 125
  • 3
  • 12
  • The systems are differnet websites. One is a internal intranet system, which doesn't display the £ symbol correctly, but saves it to the database correctly. Another system is the public facing website, which is displaying the £ symbol as expected, the 3rd system is the development public facing website, which again is not displaying the symbol correctly. I don't want to use `str_ireplace` or `htmlentities` functions it seems a hacky fix to a problem which surely has a proper solution. Thank you for your reply though. – Phil Cross Sep 14 '14 at 16:22
0

Hey i got the same problem, the ñ character display as � so i tried to put this code before selecting in database

mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");

put that code above your select statement.

i didn't try it yet in codeigniter so maybe try to use this code

$this->db->query("SET NAMES 'utf8'");
$this->db->query("SET CHARACTER SET 'utf8'");
//then your query code.

Hope this'll help.

CodeSlayer
  • 1,318
  • 1
  • 12
  • 34