RemoveDeclaration = TRUE ; $this->HasConstants = FALSE ; $this->_Constants = array() ; $this->_ContantsRegexPart = '' ; } function AddConstant( $name, $value ) { if ( strlen( $this->_ContantsRegexPart ) > 0 ) $this->_ContantsRegexPart .= '|' ; $this->_ContantsRegexPart .= $name ; $this->_Constants[ $name ] = $value ; $this->HasConstants = TRUE ; } function Process( $script ) { if ( !$this->HasConstants ) return $script; $output = $script ; if ( $this->RemoveDeclaration ) { // /var\s+(?:BASIC_COLOR_RED|BASIC_COLOR_BLUE)\s*=.+?;/ $output = preg_replace( '/var\\s+(?:' . $this->_ContantsRegexPart . ')\\s*=.+?;/m', '', $output ) ; } $output = preg_replace_callback( '/(?_ContantsRegexPart . ')(?!(?:\s*=)|\w)/', array( &$this, '_Contant_Replace_Evaluator' ), $output ) ; return $output ; } function _Contant_Replace_Evaluator( $match ) { $constantName = $match[0] ; if ( isset( $this->_Constants[ $constantName ] ) ) return $this->_Constants[ $constantName ] ; else return $constantName ; } } ?>