How to explode a multi-line string?

前端 未结 2 1652
萌比男神i
萌比男神i 2020-12-17 18:29

I have a string that has different values on each line:

$matches=\"value1
value2
value3
value4
value5
\";

I want to explode the whole strin

2条回答
  •  有刺的猬
    2020-12-17 18:54

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

提交回复
热议问题