I am trying to parse an exported inventory datafile that is exported from quickbooks (.IIF)... it is basically a tab delimited file.
I have a script that is reading the file and parsing it properly, except for one thing: quickbooks exports quantity as just a number in the file if it is less than 999. But if it is 1000 or more... instead of putting a 1000 in the file, it puts "1,000".
when my program parses the file... All I get is 1.
I tried filtering to remove the comma, but I don't think it is even loading the comma and numerals after it. How can I force the getcsv function to capture all of the data in the field (numerals and comma) and then filter out the comma to make it a number?
here is my code:
$fileopen = fopen("http://www.chasandcompany.com/invfiles/exportedqb.IIF","r"); //open the file
while ($data=fgetcsv($fileopen, 5000, "\t","\""))
{
$num = count ($data);
$row++;
for ($c=0; $c < $num; $c++)
{
if($data[$c]=="INVITEM") // beginning of an inventory item
{
if($data[4]=="INVENTORY") // make sure it is a real item
{
// fetch and clean the data
$itemnumber=$data[1];
$itemnumber=htmlspecialchars($itemnumber, ENT_QUOTES);
$mfg=$data[22];
$mfg=htmlspecialchars($mfg, ENT_QUOTES);
$datecode=$data[23];
$datecode=htmlspecialchars($datecode, ENT_QUOTES);
$quant=$data[10];
$quant=str_replace("%2C","",$quant); // clean thousands commas out of qty
$quant=htmlspecialchars($quant, ENT_QUOTES);
if($quant<=0) // make all negative qty and zero qty zero so we can match to vendor totals without adding neg numbers
{
$quant=0;
}
$description=$data[5];
$description=htmlspecialchars($description, ENT_QUOTES);
$nsn=$data[26];
$nsn=htmlspecialchars($nsn, ENT_QUOTES);
$condition=$data[25];
$condition=htmlspecialchars($condition, ENT_QUOTES);
$crossref=$data[24];
$crossref=htmlspecialchars($crossref, ENT_QUOTES);
// place row of data into array
$item[$i]['itemnumber']=$itemnumber;
$item[$i]['mfg']=$mfg;
$item[$i]['datecode']=$datecode;
$item[$i]['quant']=$quant;
$item[$i]['description']=$description;
$item[$i]['nsn']=$nsn;
$item[$i]['condition']=$condition;
$item[$i]['crossref']=$crossref;
$i=$i+1; // advance array to next item
} // end check INVENTORY variable
} // end check INVITEM
} // End For Loop
} // End While Loop
fclose($fileopen);