By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,188 Members | 844 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,188 IT Pros & Developers. It's quick & easy.

My new line \n does not work

P: 1
Hi,

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. //output;
  3. //welcome
  4. //to
  5. //ph
  6. echo "Welcome \n to \n php";
  7. ?>
The above use of \n does not give me a new line. The output is:
"Welcome to php" (all in a single line).

Please can you help.
Nov 5 '11 #1
Share this Question
Share on Google+
7 Replies


zorgi
Expert 100+
P: 431
As it should if you viewing output through your browser. However if you View -> Source you'll see what you probably expect.
Nov 5 '11 #2

Dormilich
Expert Mod 5K+
P: 8,639
or try the following
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. header("Content-Type: text/plain");
  3.  
  4. echo "Welcome \n to \n PHP";
  5. // or
  6. // echo "Welcome", PHP_EOL, "to", PHP_EOL, "PHP";
  7. ?>
Nov 7 '11 #3

P: 9
MAYBE your firewall disable pop-up message from your site or other ETC

-Nicholas
Nov 10 '11 #4

P: 9
EMAIL if you work it out!

THANKS
Nov 10 '11 #5

P: 3
Hi,
as Zorgi said,
If you view your output in a web browser, HTML ignores white space (like TAB or new lines);
To show the out put you might use either "<br />" instead of "\n" or use nl2br("Welcome \n to \n PHP")
nl2br is a php function that converts new line feed to <br /> tags.
Nov 17 '11 #6

P: 13
just add nl2br() around your printed string and you are all set.
Nov 26 '11 #7

P: 78
<?php

echo "Welcome <br> to <br> php";
?>
Dec 7 '11 #8

Post your reply

Sign in to post your reply or Sign up for a free account.