zoukankan      html  css  js  c++  java
  • php获取excel表格中数据的小方法 然后就可以放到数据库了

    现在又一个product.xml的表格文件,要求取出其中数据 
    数据如下: 

    商品名 价格
    iphone4s 4199
    note2 3999
    小米2 1999
    iphone5 4899


    1,将product.xml另存为product.csv文件 
    2,用fgetcsv函数取出其中的数据放到一个数组中(fgetcsv — 从文件指针中读入一行并解析 CSV 字段) 


    代码如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    <?php
     
    $file=fopen('./product.csv','rb');
    $data=array();//fgetcsv — 从文件指针中读入一行并解析 CSV 字段
    while($line=fgetcsv($file)){//一直取到文件结束,此事返回false
      $data[]=$line;
     
    }
    print_r($data);
     
    /*
    Array
    (
        [0] => Array
            (
                [0] => 商品名
                [1] => 价格
            )
     
        [1] => Array
            (
                [0] => iphone4s
                [1] => 4199
            )
     
        [2] => Array
            (
                [0] => note2
                [1] => 3999
            )
     
        [3] => Array
            (
                [0] => 小米2
                [1] => 1999
            )
     
        [4] => Array
            (
                [0] => iphone5
                [1] => 4899
            )
     
        [5] =>
    )
    */
     
    ?>
  • 相关阅读:
    echarts 饼图
    vue echarts
    :style :class
    弹框弹出时禁止页面滚动
    2019-2-10 日记
    2019-1-27 日记
    2019-1-26 日记
    2019-1-3 日记
    2019-1-10 日记
    2019-1-2 日记
  • 原文地址:https://www.cnblogs.com/itcx/p/3980867.html
Copyright © 2011-2022 走看看