Page 1 of 1

Read from CVS into Array and make file

Posted: Wed Oct 25, 2006 12:20 pm
by slimt_slimt
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Here is another problem! reading from file "readfrom.txt", i would like to generate config.txt with the content:

[syntax="html"]<td>name1</td>
<td>michelangelo</td>

<td>name2</td>
<td>michelangelo</td>
.
.
.
but instead the programm only reads the last part of array
name3
picasso.

Where did I go wrong - again?



readfrom.txt[/syntax]

Code: Select all

name1;michelangelo
name2;klimt
name3;picasso
code

Code: Select all

<?php
$row = 1;
$fh = fopen("readfrom.txt", "r");
while (($data = fgetcsv($fh, 512, ";")) !== FALSE) 
   {
   $num = count($data);
      $row++;
	 $nf = fopen("c://apache//htdocs//di//config.txt", "w");
    for ($c=0; $c < $num; $c++) 
	 {
	 $content = $data[$c];
	 fwrite($nf, $content);
	 echo $data[$c]. "<br />\n";
	 }
	 fclose($nf);
    }
fclose($fh);
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Oct 25, 2006 1:16 pm
by tbrown1
first thing to try is move
fclose($nf);
out so that you code reads like
}
}
fclose($nf);
fclose($fh);

I think that will fix it

Posted: Wed Oct 25, 2006 2:35 pm
by slimt_slimt
Tbrown1:
thank you for reply,
but unfortunately it doesn't work. It still saves only the last line from readfrom.txt