You are here: Re: CSV into array « PHP Programming Language « IT news, forums, messages
Re: CSV into array

Posted by Iv�n S�nchez Ortega on 10/12/05 14:24

Tom wrote:

> I have a few products stored in a csv file created in Excel. Column 1
> is the part #, column 2 is title, column 3 is color, column 4 is width
> and 5 is price.
>
> I need to read these into arrays, with a seperate array for each
> column.

Try something like:

<?php

$lines =file('whatever.csv');

foreach($lines as $line)
{
list($partno[],$title[],$color[], ... )
= explode(',',$line);
}
?>

Keep in mind that all CSV files are not equal: some use other delimiter than
comma for separating fields, some encapsulate fields within double quotes,
etc. The above code is for a trivial CSV file.

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-arroba-escomposlinux-punto-org

TAG no encontrado... Insert disk #2

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация