2

I usually use PHP to create dynamic web pages, now I need to write a script on linux that is similar to an old one I wrote for my website and I don't want to rewrite the whole thing in python.

My problem is simple, I know that '\n' is the newline character for linux, but this doesn't work:

echo 'hello world\n';

Any Ideas?

raj112
  • 38
  • 1
  • 7
  • 1
    Please also read: http://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php – vee Aug 18 '13 at 02:46
  • 2
    In a single quoted string only quotes are unescaped. use double quotes instead. – Orangepill Aug 18 '13 at 02:50

2 Answers2

6

try this for linux:

echo 'hello world'."\n";

or this (works on any OS):

echo 'hello world'.PHP_EOL;
yafrani
  • 521
  • 4
  • 9
1

In PHP, escape characters like \n are only interpreted if the string is surrounded with double quotes, so try:

echo "hello world\n";
Raman Lalia
  • 245
  • 1
  • 5