dousi1097 2013-09-11 12:27
浏览 99
已采纳

如何在读取CSV文件时修复编码?

I'm reading a CSV file in php and so far as i have understood - these kind of files can have any encoding that was ever invented by hoomans omg and so on... i guess i have a MacRoman ANSI encoded CSV, i'm working on a Mac.

So far, so good (not good at all but thats another topic).. Now, while iterating through the lines, i have a value like:

Z�rich

Obviously, it should be "Zürich" - the "ü" is missing..

Now, i have tried almost anything.. mb_detect_encoding is saying "false" so, he doesn't understand what it is...

Then i have found a genius class by Sebastian Grignoli here -> Detect encoding and make everything UTF-8

Seems nice but... all i got is:

ZŸrich

not really the "ü" i have expected :D

Now i have found out, that a "utf8_encode" will work somehow, it generates:

Z\u009Frich

but.. what now? if i put this directly in the database, the final value is "Zrich", which means it is still not really UTF-8, or is the db just struggling with the escaped variant? When i make an mb_detect_encoding on that value, he says now "UTF-8".. nice.. but how can i go further? How can i get my "Zürich" the right way in UTF-8?

  • 写回答

2条回答 默认 最新

  • douchen3562 2013-09-11 21:05
    关注

    You can probably use iconv for the conversion. On my installation, the MacRoman encoding is called simply "MAC":

    $city = "Z\x9frich";
    $city = iconv("MAC", "UTF-8", $city); 
    echo $city; // Output: Zürich
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序