Line Break Problem in .txt file

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
habib009pk
Forum Commoner
Posts: 43
Joined: Sun Jul 05, 2009 11:28 pm

Line Break Problem in .txt file

Post 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
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Line Break Problem in .txt file

Post by Mark Baker »

"\n" not '\n'
i.e. double quotes, not single quotes
habib009pk
Forum Commoner
Posts: 43
Joined: Sun Jul 05, 2009 11:28 pm

Re: Line Break Problem in .txt file

Post by habib009pk »

My Friend,

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

Regards
habib009pk
Forum Commoner
Posts: 43
Joined: Sun Jul 05, 2009 11:28 pm

Re: Line Break Problem in .txt file

Post 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);
 
Last edited by Benjamin on Thu Aug 06, 2009 6:19 am, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Line Break Problem in .txt file

Post 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));
 
Post Reply