martins256 Posted May 14, 2006 Report Share Posted May 14, 2006 <?php $text = array(); $text[0] = "1"; $text[1] = "2"; $text[2] = "3"; $text[3] = "4"; $i=0; $f=fopen('tests.txt', "a+"); while ($i <= count($text)-1) { fwrite($f, $text[$i]); echo $text[$i].'<br>'; $i++; } fclose($f); ?> izpildot šo kodu uz ekrāna katrs tabulas ieraksts izmetās jaunā rindiņā, bet failā visi ir blakām salikti. Kas jādara, lai failā katrs ieraksts būtu jaunā rindiņā ? Link to comment Share on other sites More sharing options...
wudu Posted May 14, 2006 Report Share Posted May 14, 2006 fwrite($f, $text[$i]); -> fwrite($f, $text[$i]."\r\n"); Link to comment Share on other sites More sharing options...
martins256 Posted May 14, 2006 Author Report Share Posted May 14, 2006 liels paldies Link to comment Share on other sites More sharing options...
john.brown Posted May 14, 2006 Report Share Posted May 14, 2006 (edited) Priekš tādas vajadzības tev galīgi nav nepieciešams taisīt ciklu: <?php $text = array(); $text[0] = "1"; $text[1] = "2"; $text[2] = "3"; $text[3] = "4"; $htmlcontents = implode('<br/>',$text).'<br/>'; $filecontents = implode("\r\n",$text)."\r\n"; echo $htmlcontents; $f=fopen('tests.txt', "a+"); fputs($f, $filecontents); fclose($f); ?> Ja taisi ciklu ar maing $i izmantošanu, tad tomēr laikam for() {} $count = sizeof($text); for($i = 0;$i < $count; $i++) { // kods šite } Edited May 14, 2006 by john.brown Link to comment Share on other sites More sharing options...
Delfins Posted May 15, 2006 Report Share Posted May 15, 2006 (edited) Vai arī: file_put_contents( 'mansfails.dat', serialize($mansArray) ); PS: ja failā tiek paredzēti minimāli dati Edited May 15, 2006 by Delfins Link to comment Share on other sites More sharing options...
Recommended Posts