PHP解析csv列表并将每条记录插入到wordpress用户数据库中
问题描述:
I've got an excel file containing a list of records by firstname, lastname, email_address, transaction_id
I'd like to create a script that reads in the excel data (can be csv or whatever export is easiest to work with) and inserts each record as a user in my wordpress database with the role of "member".
我有一个excel文件,其中包含firstname,lastname,email_address,transaction_id p>的记录列表
我想创建一个读取excel数据的脚本(可以是csv或任何最容易导出的导出),并将每个记录作为用户插入我的wordpress数据库中,角色为“ 成员“。 p> div>
答
You can explode each line on the delimter (like ,
) or you could use fopen
and fgetcsv
to parse line by line. Overall the general procedure is not difficult. for example:
$fileResource = fopen('/path/to/file.csv', 'r');
while(($data = fgetcsv($fileResource, ',')) !== false)
{
// $data is numeric indexed array
// do stuff with $data
}