protected function get_stripped_file_contents($fullpath) {

        $source = file_get_contents($fullpath);
        $tokens = token_get_all($source);
        $output = '';
        $doprocess = false;
        foreach ($tokens as $token) {
            if (is_string($token)) {
                // Simple one character token.
                $id = -1;
                $text = $token;
            } else {
                // Token array.
                list($id, $text) = $token;
            }
            switch ($id) {
                case T_WHITESPACE:
                case T_COMMENT:
                case T_ML_COMMENT:
                case T_DOC_COMMENT:
                    // Ignore whitespaces, inline comments, multiline comments and docblocks.
                    break;
                case T_OPEN_TAG:
                    // Start processing.
                    $doprocess = true;
                    break;
                case T_CLOSE_TAG:
                    // Stop processing.
                    $doprocess = false;
                    break;
                default:
                    // Anything else is within PHP tags, return it as is.
                    if ($doprocess) {
                        $output .= $text;
                        if ($text === 'function') {
                            // Explicitly keep the whitespace that would be ignored.
                            $output .= ' ';
                        }
                    }
                    break;
            }
        }

        return $output;
    }
protected function get_stripped_file_contents($fullpath) {

        $source = file_get_contents($fullpath);
        $tokens = token_get_all($source);
        $output = '';
        $doprocess = false;
        foreach ($tokens as $token) {
            if (is_string($token)) {
                // Simple one character token.
                $id = -1;
                $text = $token;
            } else {
                // Token array.
                list($id, $text) = $token;
            }
            switch ($id) {
                case T_WHITESPACE:
                case T_COMMENT:
                case T_ML_COMMENT:
                case T_DOC_COMMENT:
                    // Ignore whitespaces, inline comments, multiline comments and docblocks.
                    break;
                case T_OPEN_TAG:
                    // Start processing.
                    $doprocess = true;
                    break;
                case T_CLOSE_TAG:
                    // Stop processing.
                    $doprocess = false;
                    break;
                default:
                    // Anything else is within PHP tags, return it as is.
                    if ($doprocess) {
                        $output .= $text;
                        if ($text === 'function') {
                            // Explicitly keep the whitespace that would be ignored.
                            $output .= ' ';
                        }
                    }
                    break;
            }
        }

        return $output;
    }
protected function get_stripped_file_contents ( $ fullpath ) { $ source = file_get_contents ( $ fullpath ) ; $ tokens = token_get_all ( $ source ) ; $ output = '' ; $ doprocess = false ; foreach ( $ tokens as $ token ) { if ( is_string ( $ token ) ) { // Simple one character token. $ id = - 1 ; $ text = $ token ; } else { // Token array. list ( $ id , $ text ) = $ token ; } switch ( $ id ) { case T_WHITESPACE : case T_COMMENT : case T_ML_COMMENT : case T_DOC_COMMENT : // Ignore whitespaces, inline comments, multiline comments and docblocks. break ; case T_OPEN_TAG : // Start processing. $ doprocess = true ; break ; case T_CLOSE_TAG : // Stop processing. $ doprocess = false ; break ; default : // Anything else is within PHP tags, return it as is. if ( $ doprocess ) { $ output .= $ text ; if ( $ text === 'function' ) { // Explicitly keep the whitespace that would be ignored. $ output .= ' ' ; } } break ; } } return $ output ; }
Returns bare PHP code from the given file

Returns contents without PHP opening and closing tags, text outside php code,
comments and extra whitespaces.

@param string $fullpath full path to the file
@return string
Returns bare PHP code from the given file