Is a new line = \n OR \r\n?

前端 未结 4 1375
陌清茗
陌清茗 2020-11-28 08:44

I\'ve seen many developers use different methods to split a string by new lines, but i\'m confused which is the correct: \\r\\n OR \\n only?

4条回答
  •  隐瞒了意图╮
    2020-11-28 09:01

    If you are programming in PHP, it is useful to split lines by \n and then trim() each line (provided you don't care about whitespace) to give you a "clean" line regardless.

    foreach($line in explode("\n", $data))
    {
        $line = trim($line);
        ...
    }
    

提交回复
热议问题