dspx15491 2015-07-03 14:05
浏览 48
已采纳

当CSV太大而无法加载到内存时,PHP将utf-16le转换为UTF-8

Im trying to fix a CSV using PHP.

The file is also very large 500mb. I need to convert it from utf-16le to UTF-8. Issue is I used fgets() initially and found out it doesnt work with utf-16le.

How can I convert this file to UTF-8 without using fgets? The file is too big to load to memory.

I have already searched the forum and there are a lot of ways to convert the encoding but not for a file this big that uses utf-16le.

  • 写回答

1条回答 默认 最新

  • doue8385 2015-07-03 16:04
    关注

    The solution here is to leave this task to the operating system by the means of exec, shell_exec or bactick operator.

    I used:

    shell_exec ( 'iconv -f utf-16le -t utf-8 1.csv > 2.csv' );
    

    DO NOT USE FGETS FOR utf-16le!!!!!!! It will destroy the formatting of the file.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本