1.11M Members

How to insert new line character

 
0
 

<?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.

 
0
 

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

CODE
echo "this should be <br><br> a new line here <br> and here, too";

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

 
0
 

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.

Question Answered as of 6 Years Ago by DGStudios and jac39
 
0
 

tanks

 
0
 

%0A

 
0
 

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

 
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 "<script>alert('...some text...'+'php value'+'..some text...')</script>";

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

 
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.

 
0
 

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

 
1
 

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

 
0
 

this one try

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

 
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 <br /> in your php code:

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

the output would be:

line one
line two

and the source would be

<div>
line one
line two
</div>
 
0
 

You can also use this:

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

If I use double quotes I get the desired results, but not when using single quotes

    Ex. 
       $s = '<Div id="myID">\n';     //doesn't work
       $s = '<Div id="myID">'."\n";  //does work   
 
0
 

<br>
break...
"space"

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article