Replace this:
$texte = str_replace($chaine ,'',$texte);
$texte = preg_replace('/\s+/s', "\n", $texte);
with this:
$texte = preg_replace('#' . $chaine . '\s*#', "\r", $texte);
I don't know how your linebreaks look like, but try with "\r", "\n" or "\r\n" as the replacement string.