bravo14 Posted November 23, 2014 Share Posted November 23, 2014 Hi guys I am trying to echo a database record, the record is stored in polish and is stored ok. When I am echoing the data I am using the utf8_encode($row['headline']) However some of the characters are showign as ? the charset of the page is set to <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> Is there anything else I am missing or anything else may be causing the problem. Quote Link to comment Share on other sites More sharing options...
bsmither Posted November 24, 2014 Share Posted November 24, 2014 I think... Even though everyone is agreeing to use utf-8, that does not mean the font in play has the glyphs you want to show. What application are you using to verify that the database has the correct characters? What application are you using where you see the replacement character (white question mark in black diamond)? Do both use the same font? Quote Link to comment Share on other sites More sharing options...
bravo14 Posted November 24, 2014 Author Share Posted November 24, 2014 The text is showing correctly in phpmyadmin in both safari and firefox but in the same browsers the characters are showing as a quesiton mark, not the question mark in a diamond, it is also showing correctly in mysql workbench Quote Link to comment Share on other sites More sharing options...
bravo14 Posted November 25, 2014 Author Share Posted November 25, 2014 I have also changed charset of table to utf_8 and still only showing the ? Quote Link to comment Share on other sites More sharing options...
mogosselin Posted November 25, 2014 Share Posted November 25, 2014 What do you use to edit your PHP file? Check the the files the editor creates are encoded in UTF-8. Is UTF-8 your default charset with PHP? Check with phpinfo(); the value default_charset Do you use header('Content-Type: text/html; charset=utf-8'); ? Do you use any string functions on the data before echoing it? Quote Link to comment Share on other sites More sharing options...
Solution Jacques1 Posted November 25, 2014 Solution Share Posted November 25, 2014 There seems to be a whole lot of misunderstandings. The function utf8_encode() function expects an ISO 8859-1 encoded string (read the manual!) and transcodes it to UTF-8. I'm fairly sure this is not what you want. If your data already is encoded with UTF-8, the function will fail miserably. And if your data actually is ISO 8859-1, it doesn't make a terrible lot of sense to convert it to UTF-8, because this only increases the data size. A typical cause for database-related encoding issues is that the connection isn't set to the right encoding. It's not enough to declare the database as UTF-8. You also have to tell MySQL that all outgoing data should be encoded as UTF-8. Otherwise it will use the default encoding which is usually “Latin1” (a variant of ISO 8859-1). So you need to take care of three encodings: The encoding of the database itself (you seem to have already done that). The encoding of the database connection. This depends on which database extension you use. PDO? MySQLi? The old ext/mysql? For PDO, the encoding is set in the constructor, MySQL has mysqli_set_charset(), and the old extension has mysql_set_charset(). Last but not least, you have to declare the HTML document as UTF-8. This should not be done with a meta element but within the Content-Type header: Content-Type: text/html; charset=utf-8 Quote Link to comment 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.