How to explode a multi-line string?

点点圈 提交于 2019-11-29 06:40:37

You need to change '\n' to "\n".

From PHP.net:

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

\n linefeed (LF or 0x0A (10) in ASCII)
More...

Read manual

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'

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));

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!