For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > July 2005 > Re: [PHP-DB] File read question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PHP-DB] File read question
Micah Stevens

2005-07-24, 8:21 pm


What's the file format, if things are delimited, just read the first line out
from the file, after getting it with file() or something, and then use
explode() to break it up into an array based on the delimeter.

Then you can foreach through it.

Assuming it's comma seperated, this would work I think:

$file = file("filename.csv");
$columns = explode(",", $file[0]);
echo count($columns)." total columns.<br>\n";
foreach($columns as $column) {
echo "Column: $column<br>\n";
}


Is that what you mean?

-Micah

On Friday 22 July 2005 5:59 pm, Chris Payne wrote:
> Hi there everyone,
>
>
>
> I'm having to make an editor with PHP and MySQL for assigning column values
> that change (Long story), basically I can open the file and read it no
> problem, but how can I open a file and only display the first row of
> information with all columns? The column count changes every w which is
> what makes it more tricky for me.
>
>
>
> I use the fopen command to read the file and that's not an issue, I'm just
> not sure how to read the first row with all columns, any help would REALLY
> be appreciated.
>
>
>
> Regards
>
>
>
> Chris Payne

Chris Payne

2005-07-24, 8:21 pm

Hi there,

That actually looks like it might do it, thank you. I'm having a slow brain
day today :0)

Chris

What's the file format, if things are delimited, just read the first line
out
from the file, after getting it with file() or something, and then use
explode() to break it up into an array based on the delimeter.

Then you can foreach through it.

Assuming it's comma seperated, this would work I think:

$file = file("filename.csv");
$columns = explode(",", $file[0]);
echo count($columns)." total columns.<br>\n";
foreach($columns as $column) {
echo "Column: $column<br>\n";
}


Is that what you mean?

-Micah

On Friday 22 July 2005 5:59 pm, Chris Payne wrote:
> Hi there everyone,
>
>
>
> I'm having to make an editor with PHP and MySQL for assigning column

values
> that change (Long story), basically I can open the file and read it no
> problem, but how can I open a file and only display the first row of
> information with all columns? The column count changes every w which

is
> what makes it more tricky for me.
>
>
>
> I use the fopen command to read the file and that's not an issue, I'm just
> not sure how to read the first row with all columns, any help would REALLY
> be appreciated.
>
>
>
> Regards
>
>
>
> Chris Payne


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com