Iterate over each line in a string in PHP

前端 未结 7 2146
我寻月下人不归
我寻月下人不归 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:26

    preg_split the variable containing the text, and iterate over the returned array:

    foreach(preg_split("/((\r?\n)|(\r\n?))/", $subject) as $line){
        // do stuff with $line
    } 
    

提交回复
热议问题