Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

build table from external text source

 
   Database Forums (Home) -> PHP RSS
Next:  "@" before variable name  
Author Message
Richard

External


Since: Feb 14, 2007
Posts: 1



(Msg. 1) Posted: Wed Feb 14, 2007 7:27 pm
Post subject: build table from external text source
Archived from groups: alt>php (more info?)

I am completely new to PHP.

I am looking for a code snippet which would take as argument an external
text file which concists of multiple lines of 2 columns with each column
in quotes or somesuch and then generate in place a table holding that
information.

Any pointers or ideas?

 >> Stay informed about: build table from external text source 
Back to top
Login to vote
Rik

External


Since: Aug 08, 2006
Posts: 75



(Msg. 2) Posted: Wed Feb 14, 2007 7:48 pm
Post subject: Re: build table from external text source [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Wed, 14 Feb 2007 19:27:56 +0100, Richard wrote:

>
> I am completely new to PHP.
>
> I am looking for a code snippet which would take as argument an external
> text file which concists of multiple lines of 2 columns with each column
> in quotes or somesuch and then generate in place a table holding that
> information.
>
> Any pointers or ideas?

HTML table or database table? If HTML:

1. If column count is absolutely consistent:

<?php
echo '<table>;
$handle = fopen('/path/to/text/file');
while($array = fgetcsv($handle)){
echo '<tr><td>';
echo implode('</td><td>',$array);
echo '</td><tr>';
}
echo '</table>;
?>

2. If columncount not consistent or unsure:

<?php
$handle = fopen('/path/to/text/file');
$columncount = 0;
$rows = array();
while($array = fgetcsv($handle)){
$rows[] = $array;
$columncount = (count($array) > $columncount) ? count($array) :
$columncount;
}
$rowstring = '<tr>'.str_repeat('<td>%s</td>',$columncount).'</tr>';
echo '<table>';
foreach($rows as $row){
vprintf($rowstring,array_pad($row,$columncount,'');
}
echo '</table>';
?>




--
Rik Wasmus

 >> Stay informed about: build table from external text source 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
BUILD IN FUNCTION SOURCE CODE???? - I've installed php4 and Im curious about the build in function source code such as phpinfo(); Could somebody tell me where I can see these source code once php is installed in the operating system. I check all the directories with all php folders but...

BUILD IN FUNCTION SOURCE CODE???? - I've installed php4 and Im curious about the build in function source code such as phpinfo(); Could somebody tell me where I can see these source code once php is installed in the operating system. I check all the directories with all php folders but...

build tags - Dear all In my database, i have tons of information, how can i build the "tags" page? How to measure which keyword is meaningful ? thanks from Peter (cmk128@hotmail.com)

Learn how to build a simple CMS - I would to learn how to build a simple CMS (PHP/MySQL based) a tutorial, step-by-step. Any advice? Thanks in advance.

Time to build a page? Rv! - Hi How can I script a "This page took 2 seconds to build" type script. I'm having major issues with my host right now and want to gather more evidence. My scripts as stupidly simple but pages are taking over 5 seconds to trigger on one domain, ...
   Database Forums (Home) -> PHP All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]