bravo14 Posted May 28, 2014 Share Posted May 28, 2014 Hi I have a database table containing 'european' names e.g.Roman Čejka To echo this on a page I have used <?php echo utf8_encode($gp_row['reserve2']);?> However the Č is still showing as '?', any ideas what I am doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/288830-utf8_encode/ Share on other sites More sharing options...
Jacques1 Posted May 28, 2014 Share Posted May 28, 2014 However the Č is still showing as '?', any ideas what I am doing wrong? You didn't read the manual. The function utf8_encode() transcodes a string from ISO 8859-1 to UTF-8. Since your input clearly isn't ISO 8859-1, this function doesn't help you at all. I guess what you actually want is declare the character encoding of the HTML document as UTF-8 so that browsers display it correctly. Put this somewhere on top of your script: header('Content-Type: text/html;charset=utf-8'); In addition to this, you also have to set the encoding of the database connection to UTF-8: // If you're using PDO, set the character encoding in the DSN string. $database = new PDO('mysql:host=localhost;dbname=YOURDB;charset=utf8', 'YOURUSER', 'YOURPASSWORD', $options); // If you're using MySQLi, set the encoding right after the connection $database->set_charset('utf8'); // If you're still using the old MySQL extension ... mysql_set_charset('utf8'); Do not use a SET NAMES query. This silently changes the connection encoding without notifying PHP about it. As a result, all escaping functions will continue to use the old encoding and may stop working entirely. Quote Link to comment https://forums.phpfreaks.com/topic/288830-utf8_encode/#findComment-1481139 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.