-1

My code looks like this .. the o/p is a csv file with 4 values in ONE cell and so on in the FIRST column alone

Better versions of this code please . ASAP

foreach ($xml->xyz as $xyz) {  
$f = fopen('blahblahblah.csv', 'a') or die("can't open file");  
fputcsv($f, get_object_vars($lis),';','"');  
codaddict
  • 445,704
  • 82
  • 492
  • 529
Zac
  • 695
  • 1
  • 11
  • 34
  • 1
    `Better versions of this code please . ASAP` You must be kidding? – Michiel Pater Mar 21 '11 at 10:17
  • you should definitely defuse that "better versions" bit, it sounds very rude (Which I assume is not the intention.) – Unicron Mar 21 '11 at 10:25
  • Well iteration of your foreach loop, you're opening the same file and overwriting the content... assuming that it will let you open that file a second time, because you're never closing it... and for good measure, your snippet doesn't even have the closing } for the loop, so you should be getting an error – Mark Baker Mar 21 '11 at 10:25

1 Answers1

0
$f = fopen('blahblahblah.csv', 'a') or die("can't open file");    
foreach ($xml->xyz as $xyz) fputcsv($f, get_object_vars($lis),';','"');
fclose($f);

It should be fine like this.

alfmartinez
  • 179
  • 3