doujing5846 2015-01-13 07:11
浏览 18
已采纳

将具体的csv行读入php

I have one large csv file with 100000 customer details. I want to fetch data for my android application. I want to read specific row from csv file. like I want all details of customer whoes cust_id is 070507

Reading this much big file in php using this method will take too much time.

if (($handle = fopen("test.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
}
fclose($handle)
}

I want a simple solution. and If this is simplest method then please tell me how to read specific row ?

  • 写回答

2条回答 默认 最新

  • duanhuanyou6478 2015-01-13 07:25
    关注

    You can get the file into an array using file(), then you can target the specific line and parse it to CSV

    $lines = file('test.csv');
    $row = $lines[70507]; // Assuming one header row
    $csvdata = str_getcsv($row); // Parse line to CSV
    
    $num = count($data); // Get number of columns
    for ($c=0; $c < $num; $c++) { // Loop through columns
            echo $data[$c] . "<br />
    "; // Echo column
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程