src/StringFilter/StripHtmlStringFilter.php
protected function limitConsecutiveNewlines($string, $limit = 2)
    {
        // Pattern that finds any consecutive newlines that exceed the allowed limit.
        $exceeded = $limit + 1;
        $pattern = '/((\\n){' . $exceeded . ',})/';

        // Create a string with the maximum number of allowed newlines.
        $newlines = '';
        for ($i = 0; $i < $limit; $i++) {
            $newlines .= PHP_EOL;
        }

        // Find each match and replace it with the maximum number of newlines.
        return preg_replace($pattern, $newlines, $string);
    }
protected function limitConsecutiveNewlines($string, $limit = 2)
    {
        // Pattern that finds any consecutive newlines that exceed the allowed limit.
        $exceeded = $limit + 1;
        $pattern = '/((\\n){' . $exceeded . ',})/';

        // Create a string with the maximum number of allowed newlines.
        $newlines = '';
        for ($i = 0; $i < $limit; $i++) {
            $newlines .= PHP_EOL;
        }

        // Find each match and replace it with the maximum number of newlines.
        return preg_replace($pattern, $newlines, $string);
    }
protected function limitConsecutiveNewlines ( $ string , $ limit = 2 ) { // Pattern that finds any consecutive newlines that exceed the allowed limit. $ exceeded = $ limit + 1 ; $ pattern = '/((\\n){' . $ exceeded . ',})/' ; // Create a string with the maximum number of allowed newlines. $ newlines = '' ; for ( $ i = 0 ; $ i < $ limit ; $ i ++ ) { $ newlines .= PHP_EOL ; } // Find each match and replace it with the maximum number of newlines. return preg_replace ( $ pattern , $ newlines , $ string ) ; }
Restricts the number of consecutive newlines in a specific string.

@param string $string
String to limit consecutive newlines in.
@param int $limit
Limit of consecutive newlines. (Defaults to 2.)

@return string
Processed string.
Restricts the number of consecutive newlines in a specific string .