dongwen3437 2019-06-18 13:58
浏览 236

用PHP读取制表符分隔的csv

I'm not able to read a tabulator seperarated csv file (and yes, i know its csv and no tsv and the c is for tabulator...) with php and seperate it right. When i give out my imported Data with echo or readfile all the tabulators are replaced by a space and i can't use space as a sperator.

Actually i'm a bit confused that this problem is not very common when i use Google, so maybe i'm the problem...

The Problem exists with XAMPP v3.2.3 and PHP Version 7.3.5

$tempFile = fopen($tempFilePath, "r");
        $uploadData = fread($tempFile, filesize($tempFilePath));
        fclose($tempFile);

        echo $uploadData;


        $uploadData =   str_replace('"','',$uploadData);    
        $uploadData = str_replace('
','
',$uploadData);
        $uploadData = str_replace('','
',$uploadData);
        $uploadData = str_replace(';',',',$uploadData);
        $uploadData = str_replace('\t',',',$uploadData); //Here i'm trying to replace the tabulator with a colon to work with it afterwards
  • 写回答

2条回答

  • duanhuang4841 2019-06-18 14:09
    关注

    When reading a CSV file in PHP, it is best to use the fgetcsv function. With it you can specify the deliminator of the file. The function will output a row of the file. Your deliminator should be "\t".

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器