Page 1 of 1

pls help me to fix this simple thing...........

Posted: Fri Aug 28, 2009 2:20 pm
by pradeepss
hi, I have varible call $output.This variable contains following values as it is.Order is same.

7.25474,80.59846 7.25478,80.59887 7.25246,80.59804 7.25126,80.59731 7.25126,80.59731

I want to write those values into a text file.But after wrote the values into text file the order of the values in text file should be as follows.(not in same line)

7.25474,80.59846
7.25478,80.59887
7.25246,80.59804
7.25126,80.59731
7.25126,80.59731

How can i do that...pls help me with this.
Thanks in advance..

Re: pls help me to fix this simple thing...........

Posted: Fri Aug 28, 2009 2:24 pm
by Darhazer

Code: Select all

$lines = explode(' ', $output);
$fp = fopen($filename 'w+');
foreach ($lines as $line)
   fwrite($fp, $line);
fclose($fp);

Re: pls help me to fix this simple thing...........

Posted: Fri Aug 28, 2009 2:32 pm
by soapsuds
try this:

$filename="decimalpairs.txt"

$fp=fopen($filename, "w");
$out_array = explode(" ", $output);

foreach ($out_array as $outpair)
{

fwrite($fp, "$outpair\n");
}

fclose($fp);

exit(0);

Re: pls help me to fix this simple thing...........

Posted: Fri Aug 28, 2009 2:52 pm
by Darhazer
Yeah, I missed the new line... but better use PHP_EOL instead of "\n"

Re: pls help me to fix this simple thing...........

Posted: Fri Aug 28, 2009 3:45 pm
by soapsuds
Thanks I'm just learning PHP myself of didn't know what to use in lew of a UNIX newline '\n'

Re: pls help me to fix this simple thing...........

Posted: Sat Aug 29, 2009 1:22 am
by pradeepss
hey friends thanks lot.It worked well.I used PHP_EOL instead of /n.So thanks lot...............both of u guys.