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 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services