Hey Guys,
I am at work and i have to create a script to parse data from a TSV file into a database. The TSV file has to be sifted though before it is updated as they only want specific values in the database. Connecting to the DB and Using SQL is no problem for me. However for some reason my script is not outputting the data the way i want. Right now i am using fgets and explode to put the data into a 2D array, i have also used fgetcsv and i get the same results. Please see comments on where my errors are.
Script demo output is http://www.codernetworks.com/Magellon/upload.php
I feel that the code snipit below is very simple.
<?php
setlocale(LC_ALL, 'en_US.UTF-8'); //Tryed this as i was reading online.
$nFileName = "ParentFolder/UnitFolder/TestFile.tsv"; //Hidden due to security reasons.
$nRow = 1;
$nFile = fopen($nFileName, "r");
if ($nFile !== FALSE) {
while (!feof($nFile)) {
$nLineData = fgets($nFile);
//echo "$nLineData<br>"; //Debug, Works Fine.
$nParsed = explode("\t", $nLineData, -1);
echo "Parsed Line - " & $nParsed[0] & "<br>"; //Debug, Outputs Junk (eg Line 4 = @P)
echo "<br> Parsed Line - $nParsed[0] <br>"; //Debug, Outputs Proper (eg Line 4 = #START)
$nCols = count($nParsed);
$nRow++;
for ($i=0; $i < $nCols; $i++) {
//Splitting Data into a 2D Array
$nData[$nRow][$i] = $nParsed[$i];
}
}
echo "Processing Data<br>";
echo "-----------------------------------------------------<br>";
// Outputing Data from the 2D Array - Only receiving what i call junk.
echo "Test Time Stamp - " & $nData[1][1] & "<br>";
echo "Test Time Stamp - " & $nData[2][1] & "<br>";
echo "Test Time Stamp - " & $nData[3][1] & "<br>";
echo "Test Time Stamp - " & $nData[4][1] & "<br>";
echo "Test Time Stamp - " & $nData[5][1] & "<br>";
echo "Test Time Stamp - " & $nData[6][1] & "<br>";
echo "Test Time Stamp - " & $nData[7][1] & "<br>";
fclose($nFile);
}
?>