protected function removeParenthesisFromStart($token) {
        $parenthesisRemoved = 0;

        $trim = trim($token);
        if ($trim !== '' && $trim[0] === '(') { // remove only one parenthesis pair now!
            $parenthesisRemoved++;
            $trim[0] = ' ';
            $trim = trim($trim);
        }

        $parenthesis = $parenthesisRemoved;
        $i = 0;
        $string = 0;
        // Whether a string was opened or not, and with which character it was open (' or ")
        $stringOpened = '';
        while ($i < strlen($trim)) {

            if ($trim[$i] === "\\") {
                $i += 2; // an escape character, the next character is irrelevant
                continue;
            }

            if ($trim[$i] === "'") {
                if ($stringOpened === '') {
                    $stringOpened = "'";
                } elseif ($stringOpened === "'") {
                    $stringOpened = '';
                }
            }

            if ($trim[$i] === '"') {
                if ($stringOpened === '') {
                    $stringOpened = '"';
                } elseif ($stringOpened === '"') {
                    $stringOpened = '';
                }
            }

            if (($stringOpened === '') && ($trim[$i] === '(')) {
                $parenthesis++;
            }

            if (($stringOpened === '') && ($trim[$i] === ')')) {
                if ($parenthesis == $parenthesisRemoved) {
                    $trim[$i] = ' ';
                    $parenthesisRemoved--;
                }
                $parenthesis--;
            }
            $i++;
        }
        return trim($trim);
    }
protected function removeParenthesisFromStart($token) {
        $parenthesisRemoved = 0;

        $trim = trim($token);
        if ($trim !== '' && $trim[0] === '(') { // remove only one parenthesis pair now!
            $parenthesisRemoved++;
            $trim[0] = ' ';
            $trim = trim($trim);
        }

        $parenthesis = $parenthesisRemoved;
        $i = 0;
        $string = 0;
        // Whether a string was opened or not, and with which character it was open (' or ")
        $stringOpened = '';
        while ($i < strlen($trim)) {

            if ($trim[$i] === "\\") {
                $i += 2; // an escape character, the next character is irrelevant
                continue;
            }

            if ($trim[$i] === "'") {
                if ($stringOpened === '') {
                    $stringOpened = "'";
                } elseif ($stringOpened === "'") {
                    $stringOpened = '';
                }
            }

            if ($trim[$i] === '"') {
                if ($stringOpened === '') {
                    $stringOpened = '"';
                } elseif ($stringOpened === '"') {
                    $stringOpened = '';
                }
            }

            if (($stringOpened === '') && ($trim[$i] === '(')) {
                $parenthesis++;
            }

            if (($stringOpened === '') && ($trim[$i] === ')')) {
                if ($parenthesis == $parenthesisRemoved) {
                    $trim[$i] = ' ';
                    $parenthesisRemoved--;
                }
                $parenthesis--;
            }
            $i++;
        }
        return trim($trim);
    }
protected function removeParenthesisFromStart ( $ token ) { $ parenthesisRemoved = 0 ; $ trim = trim ( $ token ) ; if ( $ trim !== '' && $ trim [ 0 ] === '(' ) { // remove only one parenthesis pair now! $ parenthesisRemoved ++ ; $ trim [ 0 ] = ' ' ; $ trim = trim ( $ trim ) ; } $ parenthesis = $ parenthesisRemoved ; $ i = 0 ; $ string = 0 ; // Whether a string was opened or not, and with which character it was open (' or ") $ stringOpened = '' ; while ( $ i < strlen ( $ trim ) ) { if ( $ trim [ $ i ] === "\\" ) { $ i += 2 ; // an escape character, the next character is irrelevant continue ; } if ( $ trim [ $ i ] === "'" ) { if ( $ stringOpened === '' ) { $ stringOpened = "'" ; } elseif ( $ stringOpened === "'" ) { $ stringOpened = '' ; } } if ( $ trim [ $ i ] === '"' ) { if ( $ stringOpened === '' ) { $ stringOpened = '"' ; } elseif ( $ stringOpened === '"' ) { $ stringOpened = '' ; } } if ( ( $ stringOpened === '' ) && ( $ trim [ $ i ] === '(' ) ) { $ parenthesis ++ ; } if ( ( $ stringOpened === '' ) && ( $ trim [ $ i ] === ')' ) ) { if ( $ parenthesis == $ parenthesisRemoved ) { $ trim [ $ i ] = ' ' ; $ parenthesisRemoved -- ; } $ parenthesis -- ; } $ i ++ ; } return trim ( $ trim ) ; }
This method removes parenthesis from start of the given string.
It removes also the associated closing parenthesis.
This method removes parenthesis from start of the given string . It removes also the associated closing parenthesis .