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 optional third parameter of strstr
is not available. Is there a way to achieve this in previous versions in one line?
You can use
strpos
combined withsubstr
. First you find the position where the character is located and then you return that part of the string.Is this what you want ?
l.e. Didn't notice the one line restriction, so this is not applicable the way it is. You can combine the two functions in just one line as others suggested or you can create a custom function that will be called in one line of code, as wanted. Your choice.
not dependent from type of linebreak symbol.
$firstline now contain first line from text or empty string, if no break symbols found (or break symbol is a first symbol in text).
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.
here you go
strtok()
Documentation