Iterate over each line in a string in PHP

前端 未结 7 2099
我寻月下人不归
我寻月下人不归 2020-11-28 18:55

I have a form that allows the user to either upload a text file or copy/paste the contents of the file into a textarea. I can easily differentiate between the two and put wh

相关标签:
7条回答
  • 2020-11-28 19:42

    If you need to handle newlines in diferent systems you can simply use the PHP predefined constant PHP_EOL (http://php.net/manual/en/reserved.constants.php) and simply use explode to avoid the overhead of the regular expression engine.

    $lines = explode(PHP_EOL, $subject);
    
    0 讨论(0)
提交回复
热议问题