For replacing all line breaks with a comma, try this: $text = preg_replace( '/(\r\n)+|\r+|\n+/i', ',', $text );