I have a string with new line characters. I want to convert that string into an array, and for every new line, jump one index place in the array.
If the string is:
My text1
My text2
My text3
The result I want is this:
Array
(
[0] => My text1
[1] => My text2
[2] => My text3
)
You can use the
explodefunction, using “\n” as separator:For instance, if you have this piece of code:
You’d get this output:
Note that you have to use a double-quoted string, so
\nis actually interpreted as a line-break.(See that manual page for more details.)