Page 1 of 1
Parsing a received csv file
Posted: Thu Feb 05, 2004 4:43 am
by fastfingertips
I'm using CURL to get a balance history, and i'm trying to print the results. Also because is not my web server i cannot set the default page si i must avoid that "Virtual Directory message".
Unfortnatelly nothing haoppens
Code: Select all
<?php
function myHistory()
{
$link="https://www.e-gold.com/acct/historycsv.asp";
$pass="************";
$account="**********";
$batch="********* ";
$theString ="historycsv.asp?batchfilter=$batch";
$theString .="&PassPhrase=$pass";
$theString .="&AccountID=$account";
$ch = curl_init("https://www.e-gold.com/acct/");
$fp = fopen($theString, "r");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
curl_close($ch);
while ($data = fgetcsv($fp, 1000, ","))
{
$num = count($data);
echo "<p> $num fields in line $row: <br />\n";
$row++;
for ($c=0; $c < $num; $c++)
{
echo $data[$c] . "<br />\n";
}
}
fclose($fp);
}
?>
Posted: Thu Feb 05, 2004 7:13 am
by Weirdan
try the following:
Code: Select all
//...skipped......
//$fp = fopen($theString, "r");
$fp = fopen($theString, "w+");
//...skipped.......
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//...skipped.........
Posted: Thu Feb 05, 2004 7:32 am
by fastfingertips
w+ means to write the file and i cannot change it

. I must take only what is inside, so how can i do that?
Anyway i have tried as you said and still not working.
Posted: Thu Feb 05, 2004 11:06 am
by Weirdan
1. You need to pass to curl "writable" file pointer.
2. w+ means "read and write, truncate if exists, create if not exist"
3. To read from that pointer you need to [php_man]rewind[/php_man]($fp) after the curl_exec call.
4. Don't set CURLOPT_RETURNTRANSFER unless you want to get the response into some variable. To store response in the file you don't need this option.
Posted: Thu Feb 05, 2004 11:34 am
by fastfingertips
I've tried also to rewind but same results, a blank page:
you may take a look and perhaps give me an ideea:
http://tests.e-netarts.com/batching.php
Posted: Thu Feb 05, 2004 11:34 am
by fastfingertips
My code looks now:
Code: Select all
<?php
function myHistory()
{
$link="https://www.e-gold.com/acct/historycsv.asp";
$pass="***********";
$account="***********";
$batch="********";
$theString ="historycsv.asp?batchfilter=$batch";
$theString .="&PassPhrase=$pass";
$theString .="&AccountID=$account";
$ch = curl_init("https://www.e-gold.com/acct/");
$fp = fopen($theString, "r");
$fp = fopen($theString, "w+");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
rewind($fp);
curl_close($ch);
while ($data = fgetcsv($fp, 1000, ","))
{
$num = count($data);
echo "<p> $num fields in line $row: <br />\n";
$row++;
for ($c=0; $c < $num; $c++)
{
echo $data[$c] . "<br />\n";
}
}
fclose($fp);
}
?>
Posted: Thu Feb 05, 2004 1:28 pm
by Weirdan
Code: Select all
<?php
function myHistory()
{
$link="https://www.e-gold.com/acct/historycsv.asp";
$pass="***********";
$account="***********";
$batch="********";
$theString ="historycsv.asp?batchfilter=$batch";
$theString .="&PassPhrase=$pass";
$theString .="&AccountID=$account";
$ch = curl_init("https://www.e-gold.com/acct/");
// $fp = fopen($theString, "r");
$fp = fopen($theString, "w+");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
rewind($fp);
curl_close($ch);
while ($data = fgetcsv($fp, 1000, ","))
{
$num = count($data);
echo "<p> $num fields in line $row: <br />\n";
$row++;
for ($c=0; $c < $num; $c++)
{
echo $data[$c] . "<br />\n";
}
}
fclose($fp);
}
?>
Posted: Thu Feb 05, 2004 1:58 pm
by fastfingertips
Yes but instead to display me the results gives me "This Virtual Directory does not allow contents to be listed. " And because is a sub-domain i caanot set the default file.
Any suggestion?
Posted: Thu Feb 05, 2004 5:02 pm
by Weirdan
change this:
Code: Select all
$ch = curl_init("https://www.e-gold.com/acct/");
to this:
Code: Select all
$ch = curl_init("https://www.e-gold.com/acct/".$theString);
and try.
I think it's not issue with your script, but instead is how the e-gold works (which I know nothing about

).
Posted: Thu Feb 05, 2004 11:54 pm
by fastfingertips
The e-gold will give me a CSV file.
I was thinking to take him like a string, that using that csv function provided by PHP to format data and to display them in my page. My problem is that i cannot display the received file because it gives me that error.
I know that is a tricky problem, but i'm a curl new user

.
Any ideas?