PHP gets the data in the Excel table in a small way and then you can put it in the database.

Source: Internet
Author: User

Now another product.xml table file that asks for the data to be taken out
The data are as follows:

Product Name Price
Iphone4s 4199
Note2 3999
Xiaomi 2 1999
Iphone5 4899


1. Save Product.xml as a product.csv file
2, use the Fgetcsv function to remove the data into an array (fgetcsv-reads a line from the file pointer and resolves the CSV field)


The code is as follows:

?
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 <?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] => )*/?>

PHP gets the data in the Excel table in a small way and then you can put it in the database.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.