For many new to PHP and even for experienced once, sometimes you experience some weird behaviour and wonder why it happens? It is usually because we have not taken time to read the PHP documentation to know how specific command work and some of the behaviour we should expect of not used properly.
Once of such is the echo command. The echo command prints out to the console or page, the string delimited by single or double quotes.
echo 'This is a string'
Will output, This is a string.
It is usual for developers to use Escape sequences \n for linux and \r\n for Windows to break the string into lines.
The problem arises when you use single quotes to wrap these characters.
Take for example;
echo 'This is line 1 \n This is line 2';
This will output the unexpected result, This is line 1\nThis is line 2
The reason is that Escape sequences are only parsed when they are inside double quotes.
The above will work as follows;
echo "This is line 1 \n This is line 2";
This is line 1
This is line 2
Don’t forget to read the PHP Manual! http://php.net/manual/en/language.types.string.php