从csv文件拉取数据,并提交每行到url与curl [英] pull data from csv file and submit each row to url with curl

查看:177
本文介绍了从csv文件拉取数据,并提交每行到url与curl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找有关以下代码的指导。我有很多大的CSV文件格式为

 名字,姓氏,地址,状态,邮箱,电子邮件, dob,optindate,ipaddress,url 
Joey,Demo,4004 S. Louise Ave. 206,Sioux Falls,SD,57106,jdemo @ hotmail.com,6053231657,06 / 18 / 1944,4 / 19/2008 11:58:34,12.174.252.216,http://www.ecoupons.com

我想添加一些新的变量,将数据转换为http_build_query,并提交每一行到一个url与POST。



以下是我的代码

  $ processid ='123454r4rt5rt5rtr '; 
$ version ='1.0.0';
$ partnercode ='ABC';
$ listid ='ID12345';

$ fp = fopen(test.csv,r);

while(!feof($ fp)){
list($ firstname,$ lastname,$ address,$ city,$ state,$ zip,$ email,$ phone,$ dob ,$ optindate,$ ipaddress,$ url)= fgetcsv($ fp);
$ data = array('firstname'=> $ firstname,
'lastname'=> $ lastname,
'address'=> $ address,

'city'=> $ city,
'state'=> $ state,
'zip'=> $ zip,
'email'=>
'homephone'=> $ phone,
'dob'=> $ dob,
'optindate'=> $ optindate,
'ipaddress'=> $ ipaddress,

'url'=> $ url,
'processid'=> $ partnercode,
'version'=> $ version,
' partnercode'=> $ partnercode,
'listid'=> $ listid);

);

$ ch = curl_init();
curl_setopt($ ch,CURLOPT_URL,'https://localhost.com');
curl_setopt($ ch,CURLOPT_POST,1);

curl_setopt($ ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ ch,CURLOPT_HTTPAUTH,CURLAUTH_BASIC);
curl_setopt(CURLOPT_USERPWD,'usernameassword')

$ data = curl_exec($ ch);

curl_close($ ch);

当我现在测试时,我得到意想不到的T_VARIABLE,但我不是100%正确。



提前感谢。

解决方案

curl_setopt(CURLOPT_USERPWD,'usernameassword')应为 curl_setopt(CURLOPT_USERPWD,'usernameassword'); / p>

I am looking for guidance on the following code. I have numerous large CSV files that are in the format of

firstname,lastname,address,state,zip,email,homephone,dob,optindate,ipaddress,url
Joey,Demo,4004 S. Louise Ave. 206,Sioux Falls,SD,57106,jdemo@hotmail.com,6053231657,06/18/1944,4/19/2008 11:58:34,12.174.252.216,http://www.ecoupons.com

I am trying to add a few new variables, convert the data to a http_build_query and submit each row to a url with POST.

Here is my code

$processid = '123454r4rt5rt5rtr';
$version = '1.0.0';
$partnercode = 'ABC';
$listid = 'ID12345';

$fp= fopen("test.csv", "r");

while (!feof($fp) ) {
     list($firstname,$lastname,$address,$city,$state,$zip,$email,$phone,$dob,$optindate,$ipaddress,$url) = fgetcsv($fp);
$data = array('firstname' => $firstname,
'lastname' => $lastname,
'address' => $address,

'city' => $city,
'state' => $state,
'zip' => $zip,
'email' => $email,
'homephone' => $phone,
'dob' => $dob,
'optindate' => $optindate,
'ipaddress' => $ipaddress,

    'url' => $url,
    'processid' => $partnercode,
    'version' => $version,
    'partnercode' => $partnercode,
    'listid' => $listid);

    );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://localhost.com');
    curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt(CURLOPT_USERPWD, 'usernameassword')

$data = curl_exec($ch);

curl_close($ch);

When I am testing right now I keep getting unexpected T_VARIABLE but I am not 100% sure my coding is correct.

Thanks in advance.

解决方案

curl_setopt(CURLOPT_USERPWD, 'usernameassword') should be curl_setopt(CURLOPT_USERPWD, 'usernameassword'); with semi-colon at the end.

这篇关于从csv文件拉取数据,并提交每行到url与curl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆