protected function compileTargetCharacter($char)
    {
        switch (true) {
            case $char === 'remove':
                return function ($matches) {
                    return '';
                };

            case $char === 'keep':
                return function ($matches) {
                    return $matches[0];
                };

            case preg_match('("(?:[^\\\\"]+|\\\\\\\\|\\\\\'|\\\\")*?")', $char):
                $string = str_replace(
                    array('\\\\', '\\"', "\\'"),
                    array('\\', '"', "'"),
                    substr($char, 1, -1)
                );

                return function ($matches) use ($string) {
                    return $string;
                };

            default:
                $char = $this->compileCharacter($char);

                return function ($matches) use ($char) {
                    return $char;
                };
        }
    }
protected function compileTargetCharacter($char)
    {
        switch (true) {
            case $char === 'remove':
                return function ($matches) {
                    return '';
                };

            case $char === 'keep':
                return function ($matches) {
                    return $matches[0];
                };

            case preg_match('("(?:[^\\\\"]+|\\\\\\\\|\\\\\'|\\\\")*?")', $char):
                $string = str_replace(
                    array('\\\\', '\\"', "\\'"),
                    array('\\', '"', "'"),
                    substr($char, 1, -1)
                );

                return function ($matches) use ($string) {
                    return $string;
                };

            default:
                $char = $this->compileCharacter($char);

                return function ($matches) use ($char) {
                    return $char;
                };
        }
    }
protected function compileTargetCharacter ( $ char ) { switch ( true ) { case $ char === 'remove' : return function ( $ matches ) { return '' ; } ; case $ char === 'keep' : return function ( $ matches ) { return $ matches [ 0 ] ; } ; case preg_match ( '("(?:[^\\\\"]+|\\\\\\\\|\\\\\'|\\\\")*?")' , $ char ) : $ string = str_replace ( array ( '\\\\' , '\\"' , "\\'" ) , array ( '\\' , '"' , "'" ) , substr ( $ char , 1 , - 1 ) ) ; return function ( $ matches ) use ( $ string ) { return $ string ; } ; default : $ char = $ this -> compileCharacter ( $ char ) ; return function ( $ matches ) use ( $ char ) { return $ char ; } ; } }
Compile target into a closure, which can be used by
preg_replace_callback.

@param string $char

@return callback
Compile target into a closure which can be used by preg_replace_callback .