public static function whitespace($value, array $options = array()) {
        $options = $options + array(
            'space' => true,
            'tab' => true,
            'limit' => 2,
            'strip' => true,
            'trim' => true
        );

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

        } else {
            $pattern = '/%s+/u';
            $replace = '';
        }

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

        if ($options['space']) {
            $value = preg_replace(sprintf($pattern, ' '), (isset($replace) ? $replace : ' '), $value); // \s replaces other whitespace characters
        }

        if ($options['strip']) {
            $value = str_replace(chr(0xCA), ' ', $value);
        }

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

        return $value;
    }
public static function whitespace($value, array $options = array()) {
        $options = $options + array(
            'space' => true,
            'tab' => true,
            'limit' => 2,
            'strip' => true,
            'trim' => true
        );

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

        } else {
            $pattern = '/%s+/u';
            $replace = '';
        }

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

        if ($options['space']) {
            $value = preg_replace(sprintf($pattern, ' '), (isset($replace) ? $replace : ' '), $value); // \s replaces other whitespace characters
        }

        if ($options['strip']) {
            $value = str_replace(chr(0xCA), ' ', $value);
        }

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

        return $value;
    }
public static function whitespace ( $ value , array $ options = array ( ) ) { $ options = $ options + array ( 'space' => true , 'tab' => true , 'limit' => 2 , 'strip' => true , 'trim' => true ) ; if ( $ options [ 'limit' ] ) { $ pattern = '/%s{' . $ options [ 'limit' ] . ',}/u' ; } else { $ pattern = '/%s+/u' ; $ replace = '' ; } if ( $ options [ 'tab' ] ) { $ value = preg_replace ( sprintf ( $ pattern , '\t' ) , ( isset ( $ replace ) ? $ replace : "\t" ) , $ value ) ; } if ( $ options [ 'space' ] ) { $ value = preg_replace ( sprintf ( $ pattern , ' ' ) , ( isset ( $ replace ) ? $ replace : ' ' ) , $ value ) ; // \s replaces other whitespace characters } if ( $ options [ 'strip' ] ) { $ value = str_replace ( chr ( 0xCA ) , ' ' , $ value ) ; } if ( $ options [ 'trim' ] ) { $ value = trim ( $ value ) ; } return $ value ; }
Sanitize a string by removing excess whitespace and tab characters.

@param string $value
@param array $options {
@type bool $space   Will remove white space
@type bool $tab     Will remove tabs
@type bool $strip   Will remove non-standard white space character
@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 whitespace and tab characters .