Jump to content

[SOLVED] New Line


jj33

Recommended Posts

Im a bit new but how do you make so that you have a string

that looks like

 

<pre>

$string = "paragraph

second line

";</pre>

 

and still keep the newline.

in html i could have

<pre>paragraph\<br\>second line</pre>

Link to comment
Share on other sites

Guest Xanza

Use "\n" like unidox said...

 

 

Example Useage:

 

while($row = mysql_fetch_array($result)) {
    $out = $row["id"].',';
    $out .= $row["id_question"].',';
    $out .= $row["answer"].',';
    $out .= $row["position"].'\n';
    $out .= $row["status"].'\n';
}
    echo $out;

Link to comment
Share on other sites

Just a correction.

 

while($row = mysql_fetch_array($result)) {
   $out = $row["id"].',';
   $out .= $row["id_question"].',';
   $out .= $row["answer"].',';
   $out .= $row["position"]."\n";
   $out .= $row["status"]."\n";
}
echo $out;

 

The newline \n char will not be interpolated within single quotes.

 

so i would have

$string = "paragraph \n second line";

 

to have

paragraph

second line

 

Yes, unless of course your wanting to output html newlines, in which case you still use the <br /> tag.

Link to comment
Share on other sites

Guest Xanza
The newline \n char will not be interpolated within single quotes.

 

Ok, thanks! :) I did not know that. :) I really don't use \n to tell you the truth, I usually just use the standard HTML "<br>"... Any advantage to using \n compared to HTML - besides the quick syntax?

Link to comment
Share on other sites

Any advantage to using \n compared to HTML - besides the quick syntax?

 

A newline \n char only effects your html source code. It isn't at all relvent to html and what is output by a browser.

 

I'm in the habbit of using the \n newline simply because I do alot of shell scripting.

Link to comment
Share on other sites

Guest Xanza

jj33, what he means is

 

$string = "This is line number one \n and this is line number two";

 

will output:

 

This is line number one

and this is line number two

 

Additionally, the same effect can be obtained by using <br>

 

$string = "This is line number one<br>and this is line number two";

 

which will output:

 

This is line number one

and this is line number two

 

A newline \n char only effects your html source code. It isn't at all relvent to html and what is output by a browser.

 

I'm in the habbit of using the \n newline simply because I do alot of shell scripting.

 

Ok! Sexy, thanks for the information!

Link to comment
Share on other sites

Additionally, the same effect can be obtained by using

 

If you read my last post you will note \n and <br /> do not have the same effect at all. \n will not effect html, if you want a newline to appear in a browser you need to use htmls <br /> tag. \n will only effect the html source. ie; what you see when you rightclick->viewsource.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.