954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to insert new line character

<?php
printf("This is the first line. \n");
printf("This is the second line");
?>

This is the code but it isnt printing in new line.

mithesh
Newbie Poster
13 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 

What you need to do is use the
HTML tag before each newline character. HTML doesn't accept newlines.
So, for example :

CODE
echo "this should be

a new line here
and here, too";

You won't need to do the carriage return for a new line in the page.

jac39
Newbie Poster
3 posts since Apr 2007
Reputation Points: 10
Solved Threads: 1
 

you can make carriage returns work. HOWEVER you have to use I beileve is the pre tag. And that is kinda of messy at times. You're better off using a br tag.

just keeping options open.

DGStudios
Light Poster
31 posts since Mar 2006
Reputation Points: 10
Solved Threads: 3
 

tanks

ali_mma
Newbie Poster
1 post since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

%0A

bearcatFulton
Newbie Poster
4 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

this should be like this
printf("this is first line /n this is second line ")

piyushrock320
Newbie Poster
1 post since Apr 2011
Reputation Points: 10
Solved Threads: 0
 

Hi... friends.. I have a problem with displaying popup message box. I would like to display a popup box including php values. For example my view is..

echo "";

I think you understand my problem. i tried alot but i didn't get. So, plz. help me in this one... thank you...

sundeep_g
Newbie Poster
13 posts since Oct 2010
Reputation Points: 10
Solved Threads: 0
 

Please do not hijack old threads. But as as answer to your problem, do not use + use '.' (dot). For example,

echo "<script>alert('text".$varName."')</script>" 
//OR
echo "<script>alert('text {$varName} ')</script>"

If you have further doubts please start a new thread.

kekkaishi
Junior Poster
164 posts since Oct 2009
Reputation Points: 28
Solved Threads: 37
 

<?php
echo "This is First Line";
?>


<?php
echo "This is second line";
?>

TheOdyssey
Newbie Poster
3 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

<?php
echo "This is First line " , "
" , "This is second line ";
?>

TheOdyssey
Newbie Poster
3 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

this one try

<?php
echo "This is first line" , "
" , "This is second line";
?>

TheOdyssey
Newbie Poster
3 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 
<?php
echo "<div>\n";
echo "line one \n line two \n";
echo "</div>";
?>


the output would be

line one line two


but if you check the source, it would be

<div>
line one line two
</div>


if you want to output a newline in your html, you will have to use
in your php code:

<?php
echo "<div>\n";
echo "line one  line two \n";
echo "</div>";
?>


the output would be:

line one
line two


and the source would be

<div>
line one
line two
</div>
shadow_zed
Newbie Poster
1 post since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

You can also use this:

<?php
echo "This is first lineThis is second line";
?>
ketsi
Newbie Poster
1 post since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You