douan1893 2015-08-28 05:28
浏览 50
已采纳

注意:未定义的偏移量:2,同时使用php从csv获取数据

I was trying to fetch the data from csv to display using php.Here is the code

<?PHP

    $file_handle = fopen("dept.csv", "r");

    while (!feof($file_handle) ) {

        $line_of_text = fgetcsv($file_handle, 1024);
        print ($line_of_text[0]) . "   ". ($line_of_text[1]). ($line_of_text[2]) . "<BR>";

    }

    fclose($file_handle);

?>

I am getting the output but getting a notice msg :

Notice: Undefined offset: 2

How to solve it?

  • 写回答

1条回答 默认 最新

  • doukanhua0752 2015-08-28 05:32
    关注
    1. You don't post such questions without providing the file
    2. Appears that there are either only 2 columns in csv file or 1 of the entries does not have the third column filled in
    3. If you don't want to look into the file you can do this:

      $file_handle = fopen("dept.csv", "r");
      
      while (!feof($file_handle) ) {
      
          $line_of_text = fgetcsv($file_handle, 1024);
          print ($line_of_text[0]) . "   ". ($line_of_text[1]);
          if (isset($line_of_text[2]))
               print($line_of_text[2]);
          print ("<BR>");
      
      }
      
      fclose($file_handle);
      
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问如何在Ubuntu系统中安装使用microsoft R open?
  • ¥15 jupyter notebook
  • ¥30 informer时间序列预测
  • ¥20 SSR引物多态性分析
  • ¥15 大漠插件在Win11易语言注册调用和免注册灵异事件,VS上注册调用完全没问题
  • ¥15 Addressable缓存机制做热更新的问题
  • ¥15 微信开发者工具vant组件
  • ¥15 iPhone iCloud云盘资料删除,MAC丢失50多G桌面资料
  • ¥20 希望各位学长可以给我答疑
  • ¥20 Linux实现: 客户端(cli01)通过TCP(或UDP)连接到聊天服务器(serv)进行聊天。