Exploding a String using newline as delimiter.

Exploding a String using newline as delimiter.

Last updated:

If you have a string that's got newlines (\n) in it:

$str = "foo
        bar
        baz";

Right way:

$exploded_array = explode("\n",$str);

Wrong way:

$unexploded_array = explode('\n',$str);

As Ryan Kinal says in here,

Single quotes in PHP mean "don't parse this string".

Dialogue & Discussion