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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pradeepss
Forum Newbie
Posts: 4
Joined: Fri Aug 28, 2009 2:04 pm

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

Post 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..
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

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

Post by Darhazer »

Code: Select all

$lines = explode(' ', $output);
$fp = fopen($filename 'w+');
foreach ($lines as $line)
   fwrite($fp, $line);
fclose($fp);
soapsuds
Forum Newbie
Posts: 5
Joined: Fri Aug 28, 2009 12:53 pm

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

Post 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);
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

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

Post by Darhazer »

Yeah, I missed the new line... but better use PHP_EOL instead of "\n"
soapsuds
Forum Newbie
Posts: 5
Joined: Fri Aug 28, 2009 12:53 pm

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

Post by soapsuds »

Thanks I'm just learning PHP myself of didn't know what to use in lew of a UNIX newline '\n'
pradeepss
Forum Newbie
Posts: 4
Joined: Fri Aug 28, 2009 2:04 pm

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

Post by pradeepss »

hey friends thanks lot.It worked well.I used PHP_EOL instead of /n.So thanks lot...............both of u guys.
Post Reply