<?php $subject = "\n\n\nsubject\n\n\n";$count = 2;echo preg_replace("#\n{1,$count}\\z#",null,$subject);
Standard input is empty
subject
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!