Jump to content

CSV Line Breaks


Jellz

Recommended Posts

finished a script earlier today that scans a table in a db and extracts the email address from it, which is then exported to a csv file.

 

now im combining the second half of the script  except this time the information is coming from a csv, then performing the same operations and exporting the email address to a different csv.

 

Problem is that the imported csv has csv line break codes placed in ( "\n"). WHen i open the exported file i see weird line breaks in excel and quotes ("") in notepad. str_replace doesn't seem to remove them. Here is the code. Any thoughts?

<html>
<head>
<title>Data Manipulation</title>

</head>
<body>
<h2>Email Address Extract</h2>
<?php
$valid_Emails=array();
$findme = '@';
$line_break = "\n";
$handle = @fopen("./import.csv", "r+");
if ($handle) {
while (!feof($handle)) {
	$address = fgets($handle);
	$words= explode(' ', $address);	
	foreach ($words as $value) 
		{
			if(strpos($value,$findme) === false) {
			} else {
				array_push($valid_Emails, $value);	
			}
	}	
		} 

			}	
		$export = fopen("./export.csv", "w+");
		fputcsv($export, $valid_Emails, $line_break); 
	fclose($handle);	
	fclose($export);
	?>
            
<text>Results have been saved to export.csv</text><br />
<input type=button onClick="location.href='./export.csv'" value='Download'> 


</body>
</html> 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/171462-csv-line-breaks/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.