insert line break / carriage return at end of php string

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
inosent1
Forum Commoner
Posts: 97
Joined: Wed Jan 28, 2009 12:18 pm

insert line break / carriage return at end of php string

Post 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.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

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

Post 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.
inosent1
Forum Commoner
Posts: 97
Joined: Wed Jan 28, 2009 12:18 pm

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

Post by inosent1 »

thanks for the tip
Post Reply