Forum Moderators: coopster
Our office system supports various types of files - csv, xml, and tab delimited. I know the xml tags that are used by the system so I was thinking xml would be the easiest. If my thinking is off on this please let me know or if anyone can point me in the right direction I would really appreciate it. If I'm on the right track and just need to watch out for pitfalls, a heads up would be greatly appreciated. Thanks in advance for all of the help. I love this site as everyone has helped out immensely in the past.
Oh yeah, if anyone needs any more info. just let me know!
try to get some code and we can go from there :)
Good luck!
$DOCUMENT_ROOT = $HTTP_SERVER_VARS['DOCUMENT_ROOT'];
$fp = fopen("$DOCUMENT_ROOT/ncorders/order.csv", "r");
while(!feof($fp))
{
$order = fgetcsv($fp, ",");
$exp_order = explode(",", $order);
}
It seems to be getting stuck in this loop. I'm not too sure why. Any thoughts?
$DOCUMENT_ROOT = $HTTP_SERVER_VARS['DOCUMENT_ROOT'];
$file = "$DOCUMENT_ROOT/ncorders/order.csv";
function parse_csv_file($file, $columnheadings = true, $delimiter = ',', $enclosure = '\n') {
$row = 1;
$rows = array();
$fp = fopen("$file", "r");
while (($data = fgetcsv($fp, 0, $delimiter, $enclosure )))
{
if ($columnheadings == false && $row == 1) {
$headingTexts = $data;
}
elseif ($columnheadings == true) {
foreach ($data as $key => $value) {
unset($data[$key]);
$data[$headingTexts[$key]] = $value;
}
$rows[] = $data;
}
else {
$rows[] = $data;
}
$row++;
}
return $rows;
}
Does this look like a viable csv parser?
$file = "$DOCUMENT_ROOT/ncorders/order_variation.csv";
$row2 = 1;
$handle2 = fopen("$file", "r");
while (($data = fgetcsv($handle2, 1000, ","))!== FALSE)
{
$num = count($data);
$row2++;
for ($c = 0; $c < $num; $c++) {
echo $data[$c] . "<br />\n";
}
}
fclose($handle2);
Just need to throw an if statement to compensate for the header row and I should be golden.