1
  • currently on Wamp 2.20
  • MySQL version : 5.5.20
  • PHP version : 5.3.10
  • table collation : utf8-bin
  • header('Content-type: text/html; charset=utf-8');

while i can see the data saved in the MySQL table are the Greek characters, when i try to echo them from PHP, they turn into "?" question marks.

Adonis K. Kakoulidis
  • 4,951
  • 6
  • 34
  • 43
  • 2
    View your html source to see what is being produced. Likely you will need to encode the characters before the browser will render them appropriately. – Jared May 22 '12 at 15:43
  • 1
    You can also check the encoding of your php files. – Anas May 22 '12 at 15:44
  • check this [post](http://stackoverflow.com/questions/11806319/php-mysql-greek-letters-showing-like-marks) Its the same question. – Marios Nov 04 '13 at 19:01

3 Answers3

5

Make sure your client connection is set for UTF8. Examples:

SQL

SET NAMES UTF8;

PHP MySQLi

mysqli_set_charset('utf8');

PHP PDO

$handle = new PDO("mysql:host=localhost;dbname=dbname",
  'username', 'password', 
  array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"
));

PHP mysql (deprecated - do not use)

mysql_set_charset('utf8');
i alarmed alien
  • 9,412
  • 3
  • 27
  • 40
Ben Morley
  • 66
  • 3
2

Try using htmlentities to encode your special characters before echo'ing your data.

echo htmlentities($data);
Jared
  • 12,406
  • 1
  • 35
  • 39
2

Be sure that your file are saved using ANSI as UTF-8 aka UTF-8 without BOM. You can do it using NotePad++ : http://npp-community.tuxfamily.org/documentation/notepad-user-manual/document-properties/encoding

Also, when working with UTF-8 (Unicode) please remember :

  • All files must be saved using UTF-8 encoding ;
  • MySQL tables must be in UTF-8 ;
  • Fields in MySQL must be UTF-8 ;
  • PHP must be set to use UTF-8 ;
  • Everything has to be UTF-8 encoded.
David Bélanger
  • 7,400
  • 4
  • 37
  • 55