foggykt Posted May 4, 2011 Share Posted May 4, 2011 I have one problem...When i read from .csv file, i dont have Characters like Č,Ž,Š...Instead, its blank or some wierd characters...How to fix that? This is my code, everything works good, except for that : <?PHP $today = date("d"."."."m"."."."Y"); $file_handle = 1; $file_handle = fopen("1-ponedjeljak.csv", "r"); while (!feof($file_handle) ) { $line_of_text = fgetcsv($file_handle, 1024); echo "<tr>"; echo "<td width=70>".$line_of_text[1]."</td>"; $line_of_text[2] = mb_convert_encoding($line_of_text[2], 'UTF-8'); /*---> ive tried here but i doesnt work */ if($line_of_text[2]=="BONANZA"){ echo "<td width=700>"."<a href=\"bonanza.html?keepThis=true&TB_iframe=true&height=550&width=672\" class=\"thickbox\">BONANZA</a>"."</td>"; } else { echo "<td width=700>".$line_of_text[2]." - ".$line_of_text[3]."</td>"; } echo "<td width=90>".$line_of_text[4]."</td>"; echo "<td width=70>".$line_of_text[5]."</td>"; echo "</tr>"; } fclose($file_handle); ?> Quote Link to comment https://forums.phpfreaks.com/topic/235500-utf-8-problem-with-echo-when-reading-from-csv-file/ Share on other sites More sharing options...
vicodin Posted May 4, 2011 Share Posted May 4, 2011 When displaying the characters use htmlentities(). If you don't like using that then you need use something other than UTF-8, try ISO-8859-1. Quote Link to comment https://forums.phpfreaks.com/topic/235500-utf-8-problem-with-echo-when-reading-from-csv-file/#findComment-1210358 Share on other sites More sharing options...
foggykt Posted May 4, 2011 Author Share Posted May 4, 2011 Hmmm can you please put that in my code so that is working properly? please, im a real newbie, i would apriciate the help Quote Link to comment https://forums.phpfreaks.com/topic/235500-utf-8-problem-with-echo-when-reading-from-csv-file/#findComment-1210509 Share on other sites More sharing options...
silkfire Posted May 4, 2011 Share Posted May 4, 2011 echo "<td width=70>".utf8_decode($line_of_text[5])."</td>"; Quote Link to comment https://forums.phpfreaks.com/topic/235500-utf-8-problem-with-echo-when-reading-from-csv-file/#findComment-1210544 Share on other sites More sharing options...
btherl Posted May 5, 2011 Share Posted May 5, 2011 What is the encoding of the input file? Your call to mb_convert_encoding() says to convert to utf-8, but not what to convert from And if you are going to use utf-8 in your html, you should tell the browser to expect utf-8 : http://blogs.sitepoint.com/guide-web-character-encoding/ It's unfortunately a tricky issue to deal with properly. The basic idea is that you can tell the browser what encoding to expect using "meta http-equiv", or using HTTP headers. And you can use mb_convert_encoding() to convert from one encoding to another, but you need to tell it what encoding to convert from. If you have no idea what encoding to convert from, try iso-8859-1. Quote Link to comment https://forums.phpfreaks.com/topic/235500-utf-8-problem-with-echo-when-reading-from-csv-file/#findComment-1210706 Share on other sites More sharing options...
foggykt Posted May 5, 2011 Author Share Posted May 5, 2011 i tried ut8_decode but no luck. In my original .csv file all the letters are normal, i see ČŽŠ and all other lettters. i have <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> set in my file. i dunno, cant get it working, ive tried alot of combinations Quote Link to comment https://forums.phpfreaks.com/topic/235500-utf-8-problem-with-echo-when-reading-from-csv-file/#findComment-1210801 Share on other sites More sharing options...
foggykt Posted May 5, 2011 Author Share Posted May 5, 2011 here are my files, i really need help http://www.mediafire.com/?cg865z8ql4c7gnc Quote Link to comment https://forums.phpfreaks.com/topic/235500-utf-8-problem-with-echo-when-reading-from-csv-file/#findComment-1210802 Share on other sites More sharing options...
silkfire Posted May 5, 2011 Share Posted May 5, 2011 Hey fogg I just tried your code and file and saw no problem, the Croatian characters come up all correct. What PHP Editor are you using? Quote Link to comment https://forums.phpfreaks.com/topic/235500-utf-8-problem-with-echo-when-reading-from-csv-file/#findComment-1210828 Share on other sites More sharing options...
foggykt Posted May 5, 2011 Author Share Posted May 5, 2011 Hmmm, i use dreamweaver, and i put my php file to server and my web page shows results without thiese signs...Here you have EUVARI BAŠTINE, i need to have ČUVARI BAŠTINE. ive find some sort of solution, ive opened csv file with notepad->save as that same file, but the coding was ASCII so i changed it to UTF-8 and save. Now alomost everything works good, the only thing thats not good are strings that have first letter ČŽŠĆĐ, then the first letter is cut off Quote Link to comment https://forums.phpfreaks.com/topic/235500-utf-8-problem-with-echo-when-reading-from-csv-file/#findComment-1210861 Share on other sites More sharing options...
silkfire Posted May 5, 2011 Share Posted May 5, 2011 Fogg it really stood Euvari in the csv file, so that's something wrong with the spelning not with the source file. Were letters cut off in the screenshot too? Quote Link to comment https://forums.phpfreaks.com/topic/235500-utf-8-problem-with-echo-when-reading-from-csv-file/#findComment-1210899 Share on other sites More sharing options...
foggykt Posted May 6, 2011 Author Share Posted May 6, 2011 Hmmm, in my csv file, that ive uploaded here, it is "ČUVARI" :S In screenshot everything is ok.hmmm...well, ive managet to get it working, changed codingin csv file by opening it with notepad->save as-> and then just changed the coding to UTF-8. And then everything is ok, just words that have first letter as ĆČŠŽĐ dont show only the first letter. For example ČUVARI is echoed like UVARI, and then i just created if statement and if i have UVARI then i echo ČUVARI, and its ok. Quote Link to comment https://forums.phpfreaks.com/topic/235500-utf-8-problem-with-echo-when-reading-from-csv-file/#findComment-1211327 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.