Page 1 of 1

insert line break / carriage return at end of php string

Posted: Fri Jan 20, 2012 4:40 pm
by inosent1
i have this code:

Code: Select all

<?php
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM ldata";
$result=mysql_query ($query);
$num=mysql_num_rows ($result);
mysql_close();

$i=0;
while ($i < $num) {
$id=mysql_result($result,$i,"id");
$file_id=mysql_result($result,$i,"file_id");
$entity=mysql_result($result,$i,"entity");

$datax = $id . ';' . $file_id . ';' . $entity . '\n';

echo nl2br($datax);
++$i;
} 

?>

the string comes out looking like this:
65;53;Home Office\n13;7;Home Office\n106;90;Home Office\n
but i want it to be like:
65;53;Home Office
13;7;Home Office
106;90;Home Office
not quite sure how to do it.

Re: insert line break / carriage return at end of php string

Posted: Fri Jan 20, 2012 5:01 pm
by Celauran
If you're going to use \n, it needs to be inside double quotes. "\n" works, '\n' doesn't. You can also use PHP_EOL.

Re: insert line break / carriage return at end of php string

Posted: Fri Jan 20, 2012 5:13 pm
by inosent1
thanks for the tip