Rectangle 27 0

php How to explode a multi line string?


Also, instead of \n you can use PHP_EOL constant. In the Windows "\r\n" can be used as end of line, for this case you can make double replacement:$matches=explode("\n", str_replace("\r","\n",$matches));

Note: Unlike the double-quoted and heredoc syntaxes, variables and escape sequences for special characters will not be expanded when they occur in single quoted strings.

So use "\n" instead of '\n'

Note
Rectangle 27 0

php How to explode a multi line string?


"\n"
'\n'

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

If the string is enclosed in double-quotes ("), PHP will interpret more escape sequences for special characters:

Note
Rectangle 27 0

php How to explode a multi line string?


Also, instead of \n you can use PHP_EOL constant. In the Windows "\r\n" can be used as end of line, for this case you can make double replacement:$matches=explode("\n", str_replace("\r","\n",$matches));

Note: Unlike the double-quoted and heredoc syntaxes, variables and escape sequences for special characters will not be expanded when they occur in single quoted strings.

So use "\n" instead of '\n'

Note
Rectangle 27 0

php How to explode a multi line string?


"\n"
'\n'

If the string is enclosed in double-quotes ("), PHP will interpret more escape sequences for special characters:

Note