Obtain first line of a string in PHP

后端 未结 11 1119
醉话见心
醉话见心 2021-02-01 13:14

In PHP 5.3 there is a nice function that seems to do what I want:

strstr(input,\"\\n\",true)

Unfortunately, the server runs PHP 5.2.17 and the

11条回答
  •  礼貌的吻别
    2021-02-01 14:11

    list($line_1, $remaining) = explode("\n", $input, 2);
    

    Makes it easy to get the top line and the content left behind if you wanted to repeat the operation. Otherwise use substr as suggested.

提交回复
热议问题