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;
    }