tags:

views:

320

answers:

3

Helo,

I have the following array

$appArray=array('a', 'b', 'c');

I want to produce output such as 'a\nb\nc\n'. The trouble is that when I use

implode('\n', $appArray)

I get 'a\\nb\\nc\\n' ( note the extra backslash).

Any idea how to fix this?

+7  A: 

Are you sure you're not intending: implode("\n", $appArray)? Newline characters aren't actually treated as newline characters when encapsulated in 'single quotes'.

brianreavis
+1  A: 

Actually, in single quotes \n means \n (literally), not carriage return. Try using double quotes in implode ().

Ilya Birman
+1  A: 

Try enclosing the \n in double quotes.

It sounds like they're being interpreted as two characters: a backslash and an 'n', and the backslash is escaped with another backslash.

pavium