Re: file/array manipulation
| From: | Richard Lynch | Date: | Tue, 15 Mar 2005 16:39:27 +0000 |
| Subject: | Re: file/array manipulation | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-210830@lists.php.net to get a copy of this message | ||
> Hello
>
> I'm trying to manipulate a text(.csv) file using php. I've read the file
> and can print each line,
> but I need to write where column A is missing
>
> ColumnA ColumnB
>
> R ABC company
> ABC company
> ABC company
> ABC company
> O XYZ company
> XYZ company
> XYZ company
> XYZ company
>
> What I need to do is write a while loop (I think) to interate through the
> lines and populate ColumnA
> while ColumnB equals $var (ABC company, XYZ company), so that I end up
> with:
>
> ColumnA ColumnB
>
> R ABC company
> R ABC company
> R ABC company
> R ABC company
> O XYZ company
> O XYZ company
> O XYZ company
> O XYZ company
>
> Is this possible. What I've got so far to print out the file:
>
> $lines = file('test2.csv');
>
$category = '';
> // Loop through our array, and show line and numbers too.
> foreach ($lines as $line_num => $line) {
> echo "Line #<b>{$line_num}</b> : " . $line . "<br
> />\n";
//Assuming it's the FIRST character of each line that has space or category:
//Check first character:
if ($line[0] != ' ' && $line[0] != "\t"){
$category = $line[0];
}
echo "$category\t", trim(substr($line, 1)), "<br />\n";
> }
>
>
> Thanks in advance
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Like Music?
http://l-i-e.com/artists.htm