Split the string into an array using explode()
, use array_slice()
to get the first n elements of the newly created array. Finally join them again.
$n = 4;
$lyrics = 'line 1<br />line 2<br />line 3<br />line 4<br /><br />line 5<br />line 6<br />line 7<br />line 8';
$lines = explode('<br />', $lyrics);
echo implode('<br />', array_slice($lines, 0, $n));