EDIT 2: I come up with this kind of dirty solution, which is a function creating temporary array. It will contains the segment of the string you want to add line breaks to. Then we set it back as a string using implode.
function breakLines($str,$line_length=30,$implodechar="<br>")
{
$str_length = strlen($str);
$i=0;
$o=0;
$tmp = array();//temporary array
for ($j=0; $j<$str_length; $j++)
{
//if we are at the end of line and
//that the current char is a space or punctuation char
if($i>=$line_length && preg_match('/[\s\,\;\.\:]/isu', $str[$j]))
{
$i++;
$tmp[]=trim(substr($str,$o,$i));//"\r\n";
//we update the offset
$o+=$i;
//we reset our counter
$i=0;
}else{
$i++;
}
}
return implode($implodechar,array_filter($tmp));
}
so you can use it simply like :
echo "Lyrics: ".breakLines($this->get_lyrics($artist, $song))."</div>";
Hope it helps 🙂
EDIT: oooops, sorry I understood the contrary of what you are trying to achieve.
How about using the preg_replace function with a pattern looking for line breaks ?
echo "Lyrics: ".preg_replace('/(\R+)?/isu', '',$this->get_lyrics($artist, $song))."</div>";
I added the lower “u” modifier for handling encoding.
You can test it here : http://www.phpliveregex.com/p/ns1#preg-replace