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.