php - replace string occurrences

后端 未结 3 657
-上瘾入骨i
-上瘾入骨i 2020-12-31 10:34

I have a string \"First line | second line | third line\" How can I replace | with a new line character?

I\'m trying to use

3条回答
  •  温柔的废话
    2020-12-31 11:00

    Use this:

    str_replace('|', PHP_EOL, $str);
    

    You should use PHP_EOL instead of "\n" because PHP_EOL will always work on all server platforms. (NB. Windows uses "\r\n" and unix/linux uses "\n").

提交回复
热议问题