我正在寻找有关以下代码的指导。我有许多大型 CSV 文件,格式为
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
我正在尝试添加一些新变量,将数据转换为 http_build_query 并将每一行提交到带有 POST 的 url。
这是我的代码
$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);
当我现在测试时,我不断收到意外的 T_VARIABLE 但我不是 100% 确定我的编码是正确的。
提前致谢。