cjkeane Posted July 13, 2012 Share Posted July 13, 2012 Hi everyone, I'm sure you all have come across this issue before, and I have read a lot of posts regarding it, but I have only been able to partially resolve my issue. I have a mysql database and I'm using php to retrieve the data. I imported data from a csv into mysql and all entries which have accented characters have been mangled and appear as: �. When text is entered with accented characters and saved using php into the mysql db, the characters retain the accented characters. I'm wondering if anyone would know how to write code to check if a string e.g. (first_name) is utf-8, if not then utf-8 decode it? I believe that would solve my issue. Or if anyone else has any suggestions which might help, I'd appreciate it. Also, sometimes I notice a � will appear between lines of text when it should have been a line break. If anyone could suggest a solution to those issues, I'd appreaciate it. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/265631-php-mysql-char-set-issue-%EF%BF%BD-appears/ Share on other sites More sharing options...
scootstah Posted July 13, 2012 Share Posted July 13, 2012 What is the collation of the database table? Quote Link to comment https://forums.phpfreaks.com/topic/265631-php-mysql-char-set-issue-%EF%BF%BD-appears/#findComment-1361346 Share on other sites More sharing options...
cjkeane Posted July 13, 2012 Author Share Posted July 13, 2012 the db collation is: utf8_unicode_ci on each php page I have the following: <?php mysql_query("SET NAMES 'utf-8'"); ?> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> As I said, any new data saved via php into the mysql db retains the accented characters. It's just retrieving data (for e.g. first_name) which was imported from a csv into the mysql db which isn't displaying the accented characters correctly. Quote Link to comment https://forums.phpfreaks.com/topic/265631-php-mysql-char-set-issue-%EF%BF%BD-appears/#findComment-1361347 Share on other sites More sharing options...
scootstah Posted July 13, 2012 Share Posted July 13, 2012 Are you using LOAD DATA INFILE? If not, it might be worth a try. It is typically faster than parsing the file with PHP anyway. Quote Link to comment https://forums.phpfreaks.com/topic/265631-php-mysql-char-set-issue-%EF%BF%BD-appears/#findComment-1361348 Share on other sites More sharing options...
cjkeane Posted July 13, 2012 Author Share Posted July 13, 2012 I can't do that. The data has already been imported by someone else and merged with live data. I cannot do another import using LOAD DATA INFILE, if that's what you are asking. Quote Link to comment https://forums.phpfreaks.com/topic/265631-php-mysql-char-set-issue-%EF%BF%BD-appears/#findComment-1361349 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.