What’s the best way to remove the very first line of a text string and then echo the rest in PHP?
For example.
This is the text string:
JavaScript
x
$t=<<<EOF
First line to be removed
All the rest
Must remain
EOF;
This is the final output:
JavaScript
All the rest
Must remain
If I was working with a file in Bash I could do easily the next:
sed -i~ 1d target-file
Or:
tail -n +2 source-file > target-file
Any ideas?
Advertisement
Answer
How about preg_replace:
JavaScript
$text = "First line.nSecond line.nThird line.";
echo preg_replace('/^.+n/', '', $text);
This way you don’t need to worry about the case where there is no newline in your file.
http://codepad.org/fYZuy4LS