1

i'm using metacharacter in a simple php code, but it is now showing Second line of text into a new line.

echo "First line of text \r\n Second line of text";

I know Unix based systems use just a "\n". But as i'm on Windows 7, so i am using "/r/n"

Kanav
  • 2,695
  • 8
  • 34
  • 56
  • I assure you it is. You're probably just looking at it in a web browser with the HTML content type set (default), where whitespace doesn't matter like you think it does. (Try a `
    `.)
    – Brad Jan 08 '14 at 05:13
  • @user170654 : list of answers here: http://stackoverflow.com/questions/4238433/php-how-to-create-a-newline-character – Awlad Liton Jan 08 '14 at 05:17
  • @Brad yeah. i was looking at my browser. I figured out that it includes linebreak, tabs in the source code. Thanks all – Kanav Jan 08 '14 at 05:36

2 Answers2

1

You can use :

echo nl2br("First line of text\n Second line of text");

nl2br function

Or you can use EOL in php

Community
  • 1
  • 1
Gun2sh
  • 870
  • 12
  • 22
  • No explanation? They guy is new. You should explain your answer. – Brad Jan 08 '14 at 05:13
  • I don't see the reason for a down-voting, given the above code works – AyB Jan 08 '14 at 05:14
  • yes I also agreed with @user007, there no reason for down voting. – sas Jan 08 '14 at 05:15
  • I was writing the explanation,should havbe given me a chance,I am new too. Had to find the links. – Gun2sh Jan 08 '14 at 05:15
  • @GunnerAziz Don't post then until you have an answer. Your answer still doesn't explain what `nl2br()` does. That's why I downvoted you, and yes this absolutely warrants a downvote in my opinion. I gave you a chance... I read what you posted. I also just read your recent edit. Revise it again, and I'll read it again. That's how this works. – Brad Jan 08 '14 at 05:29
0

Try using other way with basic HTML tag <br />:

echo "First line of text" . "<br />" . "Second line of text";
Felix
  • 37,892
  • 8
  • 43
  • 55