php - Starting a newline for CSV in foreach loop? -


i need start new line every time loops through , adds csv document getting generated.

code:

if(is_array($results_top_pages->getrows())){         $name = rand();         $myfile = fopen("bin/".$name.".csv", "w") or die("unable open file!");         foreach($results_top_pages->getrows() $top_page){              $txt = array($top_page[0]. ",".$top_page[1]);              fputcsv($myfile, $txt);         }         fclose($myfile);     } 

i have tried following:

 - array($top_page[0]. ",".$top_page[1]. "\n");  - array($top_page[0]. ",".$top_page[1]. "\r\n");  - array($top_page[0]. ",".$top_page[1]. "<br>"); 

as above '' instead of ""

still no luck. generated 1 line when opened in excel.

thanks in advance.

it should detect line endings. putcsv doc:

note: if php not recognizing line endings when reading files either on or created macintosh computer, enabling auto_detect_line_endings run-time configuration option may resolve problem.

hope helps.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -