/    Sign up×
Community /Pin to ProfileBookmark

New line in php?

hi,

Can anyone please tell me how to make a new line in php:

[code=php]
echo “<tr>”;
echo “<td><input type=’checkbox’ name=’d$n’ value='”. $row->news_id.”‘></td>”;
echo “<td>$row->formatted_date</td>”;
echo “<td>”. stripslashes($row->headline) .”</td>”;
echo “<td>”. stripslashes($row->season) .”</td>”;
[/code]

I know it’s adding /n to each line, but that’s returning pesky errors?

Thanks

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@skywalker2208Jul 12.2008 — [code=php]
echo "<tr>";
echo "<td><input type='checkbox' name='d$n' value='". $row->news_id."'></td>";
echo "<td>$row->formatted_date</td>";
echo "<td>". stripslashes($row->headline) ."</td>";
echo "<td>". stripslashes($row->season) ."</td>";
[/code]


It is a back slash not a forward slash and it needs to be in double quotes.

Like this
[code=php]echo "Add a new line n";[/code]

Not like this
[code=php]
echo "This doesn't not work /n";
[/code]
Copy linkTweet thisAlerts:
@chrisbauthorJul 12.2008 — Thanks,

But say I was echoing a variable?

[code=php]
echo "$pagelinks";
[/code]
Copy linkTweet thisAlerts:
@NogDogJul 12.2008 — [code=php]
echo "$pagelinksn";
//...or...
echo $pagelinks . "n";
[/code]

Note that the "n" must be in double quotes, as it does not have this special meaning within single quotes.
Copy linkTweet thisAlerts:
@PreamJul 13.2008 — what works for me also is a return character (r) with a newline character(n)

so it would be: rn

and dont forget that escape characters must be within quotes
Copy linkTweet thisAlerts:
@IslamLoverAug 11.2013 — try this:
[code=php]echo "<br>";[/code]
this provides an HTML new line
Copy linkTweet thisAlerts:
@rootAug 11.2013 — Use the PHP_EOL which will automatically be rn or n depending on if the server is windows or a linux installation.

http://php.net/manual/en/reserved.constants.php

If you have a document that you want displayed in a web browser page (but not in a text area) then use nl2br() function to convert all newlines in to <br /> tags.
Copy linkTweet thisAlerts:
@BelrickAug 12.2013 — echo "<td>". stripslashes(nl2br($row->season))."</td>";
Copy linkTweet thisAlerts:
@rootAug 12.2013 — I think that the OP is looking for this type of thing...

[code=php]echo "<tr>" . PHP_EOL;
echo "<td><input type='checkbox' name='d$n' value='". $row->news_id."'></td>". PHP_EOL;
echo "<td>$row->formatted_date</td>". PHP_EOL;
echo "<td>". stripslashes($row->headline) ."</td>". PHP_EOL;
echo "<td>". stripslashes($row->season) ."</td>". PHP_EOL; [/code]


an alternative is to


[code=php]$out = array("<tr>",
"<td><input type='checkbox' name='d$n' value='". $row->news_id."'></td>",
"<td>$row->formatted_date</td>",
"<td>". stripslashes($row->headline) ."</td>",
"<td>". stripslashes($row->season) ."</td>");
echo implode(PHP_EOL,$out) [/code]


or use the HEREDOC method
Copy linkTweet thisAlerts:
@PurplewelshyMar 09.2015 — try this:
[code=php]echo "<br>";[/code]
this provides an HTML new line[/QUOTE]


I have tried all the suggestions here and in my Wordpress php, non have worked.

This, however did:

<?php echo "n32"; ?>

Chris.
×

Success!

Help @chrisb spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...