protected static function tokenizeByQuotesAndEscapeDependingOnContext($string)
    {
        $result = '';
        $quotesCount = substr_count($string, '"');
        $isEvenAmountOfQuotes = $quotesCount % 2 === 0;

        // go over all quote segments and apply escapePhrase inside a quoted
        // context and escapeSpecialCharacters outside the quoted context.
        $segments = explode('"', $string);
        $segmentsIndex = 0;
        foreach ($segments as $segment) {
            $isInQuote = $segmentsIndex % 2 !== 0;
            $isLastQuote = $segmentsIndex === $quotesCount;

            if ($isLastQuote && !$isEvenAmountOfQuotes) {
                $result .= '\"';
            }

            if ($isInQuote && !$isLastQuote) {
                $result .= static::escapePhrase($segment);
            } else {
                $result .= static::escapeSpecialCharacters($segment);
            }

            $segmentsIndex++;
        }

        return $result;
    }
protected static function tokenizeByQuotesAndEscapeDependingOnContext($string)
    {
        $result = '';
        $quotesCount = substr_count($string, '"');
        $isEvenAmountOfQuotes = $quotesCount % 2 === 0;

        // go over all quote segments and apply escapePhrase inside a quoted
        // context and escapeSpecialCharacters outside the quoted context.
        $segments = explode('"', $string);
        $segmentsIndex = 0;
        foreach ($segments as $segment) {
            $isInQuote = $segmentsIndex % 2 !== 0;
            $isLastQuote = $segmentsIndex === $quotesCount;

            if ($isLastQuote && !$isEvenAmountOfQuotes) {
                $result .= '\"';
            }

            if ($isInQuote && !$isLastQuote) {
                $result .= static::escapePhrase($segment);
            } else {
                $result .= static::escapeSpecialCharacters($segment);
            }

            $segmentsIndex++;
        }

        return $result;
    }
protected static function tokenizeByQuotesAndEscapeDependingOnContext ( $ string ) { $ result = '' ; $ quotesCount = substr_count ( $ string , '"' ) ; $ isEvenAmountOfQuotes = $ quotesCount % 2 === 0 ; // go over all quote segments and apply escapePhrase inside a quoted // context and escapeSpecialCharacters outside the quoted context. $ segments = explode ( '"' , $ string ) ; $ segmentsIndex = 0 ; foreach ( $ segments as $ segment ) { $ isInQuote = $ segmentsIndex % 2 !== 0 ; $ isLastQuote = $ segmentsIndex === $ quotesCount ; if ( $ isLastQuote && ! $ isEvenAmountOfQuotes ) { $ result .= '\"' ; } if ( $ isInQuote && ! $ isLastQuote ) { $ result .= static :: escapePhrase ( $ segment ) ; } else { $ result .= static :: escapeSpecialCharacters ( $ segment ) ; } $ segmentsIndex ++ ; } return $ result ; }
This method is used to escape the content in the query string surrounded by quotes
different then when it is not in a quoted context.

@param string $string
@return string
This method is used to escape the content in the query string surrounded by quotes different then when it is not in a quoted context .