开发者

PHP import CSV with utf-8 accents

I am having issues importing a CSV file which contains (french) names with accents in them... when ever they are imported the accent do not display properly example

félix turns into fŽlix

the file is created by hand开发者_开发技巧 and then imported into PHP.

I have tried both utf8_encode() and utf8_decode() and nether function will convert the chars so they can be viewed properly.

my question is how can i get this to render properly... convert char-set.. etc

I believe the text is encoded in Cp850 based on other questions i've seen on here. I am using fgetcvs() to get the contents.


Set Header Information before you output as UTF

header('Content-Type: text/html; charset=utf-8');
$log = file_get_contents("log.csv");
echo utf8_encode($log);

Output

félix


Please, try iconv() function


I think this is late answer but may be helpful for those who are still searching for solution. This is just a tweak. Not always recommended .

header('Content-Encoding: UTF-8');
header('Content-type: text/csv; charset=UTF-8');
header('Content-Disposition: attachment; filename=filename.csv');
echo "\xEF\xBB\xBF"; // UTF-8 with BOM
readfile("filename.csv");
exit;


I'm doing this on upload

if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_dir .$target_file)) {
      $log = file_get_contents($target_dir .$target_file);
      file_put_contents($target_dir .$target_file, utf8_encode($log));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜