private function stripWhitespace($source)
    {
        // Verificar se token_get_all existe
        if (! function_exists('token_get_all')) {
            return $source;
        }

        $output = '';
        foreach (token_get_all($source) as $token) {
            if (is_string($token)) {
                $output .= $token;
            } elseif (in_array($token[0], [T_COMMENT, T_DOC_COMMENT])) {
                $output .= str_repeat("\n", substr_count($token[1], "\n"));
            } elseif (T_WHITESPACE === $token[0]) {
                // reduce wide spaces
                $whitespace = preg_replace('{[ \t]+}', ' ', $token[1]);
                // normalize newlines to \n
                $whitespace = preg_replace('{(?:\r\n|\r|\n)}', "\n", $whitespace);
                // trim leading spaces
                $whitespace = preg_replace('{\n +}', "\n", $whitespace);
                $output .= $whitespace;
            } else {
                $output .= $token[1];
            }
        }

        return $output;
    }
private function stripWhitespace($source)
    {
        // Verificar se token_get_all existe
        if (! function_exists('token_get_all')) {
            return $source;
        }

        $output = '';
        foreach (token_get_all($source) as $token) {
            if (is_string($token)) {
                $output .= $token;
            } elseif (in_array($token[0], [T_COMMENT, T_DOC_COMMENT])) {
                $output .= str_repeat("\n", substr_count($token[1], "\n"));
            } elseif (T_WHITESPACE === $token[0]) {
                // reduce wide spaces
                $whitespace = preg_replace('{[ \t]+}', ' ', $token[1]);
                // normalize newlines to \n
                $whitespace = preg_replace('{(?:\r\n|\r|\n)}', "\n", $whitespace);
                // trim leading spaces
                $whitespace = preg_replace('{\n +}', "\n", $whitespace);
                $output .= $whitespace;
            } else {
                $output .= $token[1];
            }
        }

        return $output;
    }
private function stripWhitespace ( $ source ) { // Verificar se token_get_all existe if ( ! function_exists ( 'token_get_all' ) ) { return $ source ; } $ output = '' ; foreach ( token_get_all ( $ source ) as $ token ) { if ( is_string ( $ token ) ) { $ output .= $ token ; } elseif ( in_array ( $ token [ 0 ] , [ T_COMMENT , T_DOC_COMMENT ] ) ) { $ output .= str_repeat ( "\n" , substr_count ( $ token [ 1 ] , "\n" ) ) ; } elseif ( T_WHITESPACE === $ token [ 0 ] ) { // reduce wide spaces $ whitespace = preg_replace ( '{[ \t]+}' , ' ' , $ token [ 1 ] ) ; // normalize newlines to \n $ whitespace = preg_replace ( '{(?:\r\n|\r|\n)}' , "\n" , $ whitespace ) ; // trim leading spaces $ whitespace = preg_replace ( '{\n +}' , "\n" , $ whitespace ) ; $ output .= $ whitespace ; } else { $ output .= $ token [ 1 ] ; } } return $ output ; }
Removes whitespace from a PHP source string while preserving line numbers.

@param  string $source A PHP string
@return string The PHP string with the whitespace removed
Removes whitespace from a PHP source string while preserving line numbers .