Hi everyone,
basicly I have a CSV file which uses ^ as a delimiter. I have a textarea which is populated by the contents of the CSV file, and after editing it the user is redirected to the edit page.
For some reason, everytime I save the file there is a line which is added between each line of text. I want to get rid of the empty lines.
Edit.php
<form action="save.php" method="post">
<textarea name="events" cols="100" rows="10" style="text-align:left">
<?php
if (($handle=fopen("events.csv","r"))!==FALSE)
{
$rowNo=1;
while (($data = fgetcsv($handle, 1000, "^")) !== FALSE)
{
$num=count($data);
$data=str_replace("’","'",$data);?>
<?php
if ($rowNo==1)
{
for ($c=0; $c < $num; $c++)
{
echo $data[$c];
}
}
else
{
for ($c=0; $c < $num; $c++)
{
echo $data[$c];
if ($c==($num-1))
{
}
else
{
echo "^";
}
}
}
?>
<?php
$rowNo++;
}
}
?>
</textarea><br />
<input type="submit" name="Edit" value="Save" />
</form>
Save.php
<?php
$events=$_POST['events'];
$myFile = "events.csv";
$fh = fopen($myFile, 'w') or die("can't open file");
$events=str_replace("’","'",$events);
$events = stripcslashes($events);
fwrite($fh,$events);
fclose($fh);
header('Location:edit.php');
?>
Example of events.csv
Events / Summer 2010
Milkshake Disco^A disco for 6 to 10 year olds^Friday 28th May^Friday 25th June
Summer Project^A project running from Mon - Thurs for 6 to 10 year olds^August 2nd to 26th
What do I do to get rid of the lines that are added?
Cheers,
Ben