phppaper Posted April 19, 2011 Share Posted April 19, 2011 Dear all, anyone of you has experience on using PHP to write content to CSV? I cannot display symbols letter such as ìíóò. Any idea? Quote Link to comment https://forums.phpfreaks.com/topic/234138-write-%C3%AC%C3%AD%C3%B3%C3%B2-letter-to-csv-and-display-out/ Share on other sites More sharing options...
Adam Posted April 19, 2011 Share Posted April 19, 2011 An easy solution to this is to convert the characters to HTML entities, using the htmlentities function. You can then use html_entity_decode to decode them, if needed. If you're outputting to a web page it's better to leave them as HTML entities however. Quote Link to comment https://forums.phpfreaks.com/topic/234138-write-%C3%AC%C3%AD%C3%B3%C3%B2-letter-to-csv-and-display-out/#findComment-1203382 Share on other sites More sharing options...
phppaper Posted April 20, 2011 Author Share Posted April 20, 2011 Thanks for the answer but after htmlentities() and html_entity_decode() the ìíóò into the csv, I still get funny symbols. and the html translate is wrong aswell, example I get for í : ó which I support to get í but I get ó Any thought? Quote Link to comment https://forums.phpfreaks.com/topic/234138-write-%C3%AC%C3%AD%C3%B3%C3%B2-letter-to-csv-and-display-out/#findComment-1203808 Share on other sites More sharing options...
The Little Guy Posted April 20, 2011 Share Posted April 20, 2011 if the data is comming from a database, you could use mysql SELECT a,b,a+b INTO OUTFILE '/tmp/result.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' FROM test_table; Quote Link to comment https://forums.phpfreaks.com/topic/234138-write-%C3%AC%C3%AD%C3%B3%C3%B2-letter-to-csv-and-display-out/#findComment-1203811 Share on other sites More sharing options...
phppaper Posted April 20, 2011 Author Share Posted April 20, 2011 thanks, the data do from database but first we have to use php to do some operations and also what I need to solve is the ì í ó ò letter cannot display properly in csv. Any solution? Quote Link to comment https://forums.phpfreaks.com/topic/234138-write-%C3%AC%C3%AD%C3%B3%C3%B2-letter-to-csv-and-display-out/#findComment-1203814 Share on other sites More sharing options...
The Little Guy Posted April 20, 2011 Share Posted April 20, 2011 encode them to utf8: utf8_encode also: http://www.phpfreaks.com/forums/index.php?topic=275241.0 Quote Link to comment https://forums.phpfreaks.com/topic/234138-write-%C3%AC%C3%AD%C3%B3%C3%B2-letter-to-csv-and-display-out/#findComment-1203816 Share on other sites More sharing options...
phppaper Posted April 20, 2011 Author Share Posted April 20, 2011 I have tried it, the result is a different funny symbol . I have also tried iconv, not working. Quote Link to comment https://forums.phpfreaks.com/topic/234138-write-%C3%AC%C3%AD%C3%B3%C3%B2-letter-to-csv-and-display-out/#findComment-1203817 Share on other sites More sharing options...
The Little Guy Posted April 20, 2011 Share Posted April 20, 2011 did you tell the app (excel/open office/etc.) to use utf8 to read the data? Quote Link to comment https://forums.phpfreaks.com/topic/234138-write-%C3%AC%C3%AD%C3%B3%C3%B2-letter-to-csv-and-display-out/#findComment-1203819 Share on other sites More sharing options...
phppaper Posted April 20, 2011 Author Share Posted April 20, 2011 good suggestion, but it is not possible to ask the user to do so, that why the system has to make in a away to work without the need to alter anything on the client side. Quote Link to comment https://forums.phpfreaks.com/topic/234138-write-%C3%AC%C3%AD%C3%B3%C3%B2-letter-to-csv-and-display-out/#findComment-1203821 Share on other sites More sharing options...
The Little Guy Posted April 20, 2011 Share Posted April 20, 2011 There really is only so much you can do to help a user, you can't be responsible for their retardedness. but I guess MrAdam has a good point, not sure if it will work.. $decoded_string = html_entity_decode($string, ENT_QUOTES, 'UTF-8'); Quote Link to comment https://forums.phpfreaks.com/topic/234138-write-%C3%AC%C3%AD%C3%B3%C3%B2-letter-to-csv-and-display-out/#findComment-1203822 Share on other sites More sharing options...
phppaper Posted April 20, 2011 Author Share Posted April 20, 2011 Thanks, but that function does not support UTF-8 and therefore it shows an error. Quote Link to comment https://forums.phpfreaks.com/topic/234138-write-%C3%AC%C3%AD%C3%B3%C3%B2-letter-to-csv-and-display-out/#findComment-1203826 Share on other sites More sharing options...
The Little Guy Posted April 20, 2011 Share Posted April 20, 2011 Yes it does. What is the error? Quote Link to comment https://forums.phpfreaks.com/topic/234138-write-%C3%AC%C3%AD%C3%B3%C3%B2-letter-to-csv-and-display-out/#findComment-1203828 Share on other sites More sharing options...
phppaper Posted April 20, 2011 Author Share Posted April 20, 2011 cannot yet handle MBCS in html_entity_decode() but I rewrite the function: $utf8_encode = utf8_encode(html_entity_decode($string)); according to http://php.net/manual/en/function.html-entity-decode.php Still funny symbol showing Quote Link to comment https://forums.phpfreaks.com/topic/234138-write-%C3%AC%C3%AD%C3%B3%C3%B2-letter-to-csv-and-display-out/#findComment-1203831 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.