fgetcsv() delimiters ?
| From: | Chris Blake | Date: | Tue, 08 Apr 2003 13:03:49 +0000 |
| Subject: | fgetcsv() delimiters ? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-142851@lists.php.net to get a copy of this message | ||
Greetings learned PHP(eople)
The following code opens a text file and puts all the lines in the file
into an array, so that I can take each line and compile a nice table
with the order info in it.
//---------------------------------------------------------------------
<?php
@ $fp = fopen("$DOCUMENT_ROOT/PHP101/Chapter2/orders.txt", 'r');
if (!$fp)
{
echo '<p><strong>No orders pending.'
.'Please try again later.</strong></p>';
exit;
}
echo "\n" . '<table border="1">' . "\n";
echo '<tr>' . "\n";
echo '<td>Date Ordered</td>' . "\n";
echo '<td>Items Ordered</td>' . "\n";
echo '<td>Amount</td>' . "\n";
echo '<td>Delivery Address</td>' . "\n";
echo '</tr>';
while (!feof($fp))
{
//This gets each line in the text file and places them in an array
$order = fgetcsv($fp, 100, "\t");
//This one just reads the entire line without seperating values
//$order= fgets($fp, 999);
echo '<tr>' . "\n";
echo '<td>' . $order[0] . '</td>';
echo '<td>' . $order[1] . '</td>';
echo '<td>' . $order[2] . '</td>';
echo '<td>' . $order[3] . '</td>';
echo '<td>' . $order[4] . '</td>';
echo '<td>' . $order[5] . '</td>';
echo '</tr>';
}
echo '</table>' . "\n";
fclose($fp);
?>
//-------------------------------------------------------------------------------
The problem is, I`m using the tab delimiter with fgetcsv(), but some of
the entries in the file were not entered using this format. Looking at
the text file content in vim it appears that a single space is used, or
some other delimiter.
Do I need to loop through the file again using fgetcsv(), this time
using another delimiter value ?
Thanks for any help you may offer.
--
Chris Blake
Office : (011) 782-0840
Cell : 083 985 0379
Linux vs. Windows is a no WIN situation.