public static function newlines($value, array $options = array()) {
        $options = $options + array(
            'cr' => true,
            'lf' => true,
            'crlf' => true,
            'limit' => 2,
            'trim' => true
        );

        if ($options['limit']) {
            $pattern = '/(?:%s){' . $options['limit'] . ',}/u';

        } else {
            $pattern = '/(?:%s)+/u';
            $replace = '';
        }

        if ($options['crlf']) {
            $value = preg_replace(sprintf($pattern, '\r\n'), (isset($replace) ? $replace : "\r\n"), $value);
        }

        if ($options['cr']) {
            $value = preg_replace(sprintf($pattern, '\r'), (isset($replace) ? $replace : "\r"), $value);
        }

        if ($options['lf']) {
            $value = preg_replace(sprintf($pattern, '\n'), (isset($replace) ? $replace : "\n"), $value);
        }

        if ($options['trim']) {
            $value = trim($value);
        }

        return $value;
    }
public static function newlines($value, array $options = array()) {
        $options = $options + array(
            'cr' => true,
            'lf' => true,
            'crlf' => true,
            'limit' => 2,
            'trim' => true
        );

        if ($options['limit']) {
            $pattern = '/(?:%s){' . $options['limit'] . ',}/u';

        } else {
            $pattern = '/(?:%s)+/u';
            $replace = '';
        }

        if ($options['crlf']) {
            $value = preg_replace(sprintf($pattern, '\r\n'), (isset($replace) ? $replace : "\r\n"), $value);
        }

        if ($options['cr']) {
            $value = preg_replace(sprintf($pattern, '\r'), (isset($replace) ? $replace : "\r"), $value);
        }

        if ($options['lf']) {
            $value = preg_replace(sprintf($pattern, '\n'), (isset($replace) ? $replace : "\n"), $value);
        }

        if ($options['trim']) {
            $value = trim($value);
        }

        return $value;
    }
public static function newlines ( $ value , array $ options = array ( ) ) { $ options = $ options + array ( 'cr' => true , 'lf' => true , 'crlf' => true , 'limit' => 2 , 'trim' => true ) ; if ( $ options [ 'limit' ] ) { $ pattern = '/(?:%s){' . $ options [ 'limit' ] . ',}/u' ; } else { $ pattern = '/(?:%s)+/u' ; $ replace = '' ; } if ( $ options [ 'crlf' ] ) { $ value = preg_replace ( sprintf ( $ pattern , '\r\n' ) , ( isset ( $ replace ) ? $ replace : "\r\n" ) , $ value ) ; } if ( $ options [ 'cr' ] ) { $ value = preg_replace ( sprintf ( $ pattern , '\r' ) , ( isset ( $ replace ) ? $ replace : "\r" ) , $ value ) ; } if ( $ options [ 'lf' ] ) { $ value = preg_replace ( sprintf ( $ pattern , '\n' ) , ( isset ( $ replace ) ? $ replace : "\n" ) , $ value ) ; } if ( $ options [ 'trim' ] ) { $ value = trim ( $ value ) ; } return $ value ; }
Sanitize a string by removing excess CRLF characters.

@param string $value
@param array $options {
@type bool $cr      Will remove carriage returns \r
@type bool $lf      Will remove line feeds \n
@type bool $crlf    Will remove CRLF \r\n
@type bool $trim    Will remove whitespace and newlines around the edges
@type int $limit    The start limit to remove extraneous characters
}
@return string
Sanitize a string by removing excess CRLF characters .