[fwd] RE: [thelist] Reading CSV in PHP
john corry
john at neoncowboy.com
Sun Sep 30 11:41:27 CDT 2001
---------------------------------------------
This message was held by thelist software and
is being manually forwarded by a list admin.
Please remember to send emails in plain-text
format only, or they will not reach thelist
until it is later forwarded by a list admin.
---------------------------------------------
Here's a well commented fiel that does just that...
##########################
<?php
// open the text file
$fd = fopen ("pilots.csv", "r");
// initialize a loop to go through each line of the file
while (!feof ($fd)) {
// declare an array to hold all of the contents of each row, indexed
$buffer = fgetcsv($fd, 4096);
// start a row for the table
echo "<tr>\n";
// this for loop is the meat, the 17 represents the number of columns in
the text file, hey...the world is a hack!
// when this is re-created with MySQL use the mysql_num_fileds() function
to get this number
for ($i = 0; $i < 17; ++$i){
// if the field is empty, make it = ' ' so NN doesn't puke on an
empty
<td>
if ($buffer[$i] == ""){
$buffer[$i] = " ";
}
// if its the email field, construct a mailto link
if ($i == 5 && $buffer[$i] !=" " && $buffer[$i] !="email" ){
$buffer[$i] = "<a href=\"mailto:$buffer[$i]\">$buffer[$i]</a>";
}
// print <td>'s with each index
echo "<td class=\"list\">$buffer[$i]</td>\n";
}
echo "</tr>\n";
}
fclose ($fd);
?>
##########################
> -----Original Message-----
> From: thelist-admin at lists.evolt.org
> [mailto:thelist-admin at lists.evolt.org]On Behalf Of Gustavo Arizpe
> Sent: Saturday, September 29, 2001 6:54 PM
> To: thelist at lists.evolt.org
> Subject: [thelist] Reading CSV in PHP
>
>
> Does anyone know of a PHP script to read and nicely display data from
> comma-separated data files? This would be used for a small book catalog,
> displaying images, book title and description.
> Thanks!
>
> Gustavo
>
>
More information about the thelist
mailing list