Page 1 of 1

Line Break Problem in .txt file

Posted: Thu Aug 06, 2009 5:18 am
by habib009pk
Hi Friends,

I am facing a problem i want to create a file from different variables having date i.e:
$cheadline or $qsummary.

Now after cancatenation of these variables i have another variable that is $combine.

$combine=$cheadline.'\n'.$qsummary.'\n'.$fpara.'\n'.$lsentence.'\n'.$summrize.'\n'.$cinfo;

When i am using that code

$handle = fopen($filename, "w");
fwrite($handle,$combine);

Then file will be created but all the data are written on same line, without line break.

Please help me how can i break the line after the data of each variable.

Thank and Regards

Re: Line Break Problem in .txt file

Posted: Thu Aug 06, 2009 5:21 am
by Mark Baker
"\n" not '\n'
i.e. double quotes, not single quotes

Re: Line Break Problem in .txt file

Posted: Thu Aug 06, 2009 5:27 am
by habib009pk
My Friend,

Thanks but it is not Working, I also tested it..

Regards

Re: Line Break Problem in .txt file

Posted: Thu Aug 06, 2009 5:55 am
by habib009pk
Thanks for you Cooperation

It is solved by that code my self

Code: Select all

 
$seperate="
 
";
$string=$cheadline.$seperate.$qsummary.$seperate.$fpara.$seperate.$lsentence.$seperate.$summrize.$seperate.$cinfo.$seperate;
 
$filename = "file.txt";
$handle = fopen($filename, "w");
fwrite($handle,$string);
fclose($handle);
 

Re: Line Break Problem in .txt file

Posted: Thu Aug 06, 2009 6:23 am
by Benjamin
Mark Baker provided you with a correct response. You may want carriage returns as well. In that case either of the following would work.

Code: Select all

 
$string= "$cheadline\r\n$qsummary\r\n$fpara\r\n$lsentence\r\n$summrize\r\n$cinfo\n";
 
$string = implode("\r\n", array($cheadline, $qsummary, $fpara, $lsentence, $summrize, $cinfo));