new line break in php

How to use new line break in php

Page 1 of 1

6 Replies - 235041 Views - Last Post: 12 August 2010 - 07:09 AM Rate Topic: -----

#1 david4u  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 38
  • Joined: 26-April 06

new line break in php

Posted 29 April 2006 - 06:40 AM

I want to put a new line break on the records that i am retrive using CVS file. I am retrieving data from mysql database into a csv file but could not break up the data when it is displayed. This is how it is displaying below:

1,4,Yes ,1\nenabled\n1,4,Yes ,1\nenabled\n2,4,No ,2\nenabled\n1,4,Yes ,1\nenabled\n2,4,No ,2\nenabled\n3,4,Not sure ,3\nenabled\n1,4,Yes


I need to put a new line break on the code below. Can someone identify my error or tell me how to use new line break in php please.

while ($row = mysql_fetch_array($result)) {
  // this sticks the results row by row into an array called $row.
  // rows are called via $array_name["COLUMN_NAME"]
	//$out  = 
	$out .= $row["id"].',';
	$out .= $row["id_question"].',';
	$out .= $row["answer"].',';
	$out .= $row["position"].'\n';
	$out .= $row["status"].'\n';


	echo $out;


Thanks.

Is This A Good Question/Topic? 1

#26 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: new line break in php

Posted 29 April 2006 - 07:41 AM

Put the newline charactor (\n) in double quotes, ".

echo "This is\na newline";
//Depending on what the server is running off of...
//Linux you just need to use \n
//Mac OS needs both \r\n to make a newline and return to the start.
//And for Windows \n is all you need


Was This Post Helpful? 1

#27 zerodotcom  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 14-November 07

Re: new line break in php

Posted 14 November 2007 - 12:24 AM

<ignore me>

This post has been edited by zerodotcom: 14 November 2007 - 12:25 AM

Was This Post Helpful? 0
  • +
  • -

#31 prathyush  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 1
  • Joined: 19-February 09

Re: new line break in php

Posted 19 February 2009 - 09:09 PM

View Postdavid4u, on 29 Apr, 2006 - 05:40 AM, said:

I want to put a new line break on the records that i am retrive using CVS file. I am retrieving data from mysql database into a csv file but could not break up the data when it is displayed. This is how it is displaying below:

1,4,Yes ,1\nenabled\n1,4,Yes ,1\nenabled\n2,4,No ,2\nenabled\n1,4,Yes ,1\nenabled\n2,4,No ,2\nenabled\n3,4,Not sure ,3\nenabled\n1,4,Yes


I need to put a new line break on the code below. Can someone identify my error or tell me how to use new line break in php please.

while ($row = mysql_fetch_array($result)) {
  // this sticks the results row by row into an array called $row.
  // rows are called via $array_name["COLUMN_NAME"]
	//$out  = 
	$out .= $row["id"].',';
	$out .= $row["id_question"].',';
	$out .= $row["answer"].',';
	$out .= $row["position"].'\n';
	$out .= $row["status"].'\n';


	echo $out;


Thanks.


Hello you need to put \n in double quotes like follws
$out .= $row["status"]."\n";
Was This Post Helpful? 1

#56 Kirth  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 157
  • Joined: 09-July 08

Re: new line break in php

Posted 23 February 2009 - 07:43 AM

Double quotes = Stuff like \\, \n, \r, gets escaped.
Single quotes = No escaping.
Was This Post Helpful? 1

#57 donavn  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 1
  • Joined: 08-December 09

Re: new line break in php

Posted 08 December 2009 - 11:43 PM

insert new line in SQL is "\r\n"
in html is "<br>"
nl2br($str) is convert "\r\n" to "<br>"
Was This Post Helpful? 1

#58 Guest_Yaisr Siddiqui*


Reputation:

Re: new line break in php

Posted 12 August 2010 - 07:09 AM

Hi, This may help you this code is tested and run on windows as well.

$strFilePath = '/path/to/file.txt';
$strFileContents = '';
 
// Check that file exists and is readable
if(true === file_exists($strFilePath) && true === is_readable($strFilePath)) {
    $strFileContents = file_get_contents($strFilePath);
}
 
$strFileContents .= "$strNewContent\r\n";
file_put_contents($strFilePath, $strFileContents);



Yasir Siddiqui
Thanx

This post has been edited by no2pencil: 12 August 2010 - 06:35 PM
Reason for edit:: Added code tags

Was This Post Helpful? 0

Page 1 of 1