src/Encoder/StringEncoder.php
private function getDoubleQuotedString($string, $options)
    {
        $string = strtr($string, [
            "\n" => '\n',
            "\r" => '\r',
            "\t" => '\t',
            '$' => '\$',
            '"' => '\"',
            '\\' => '\\\\',
        ]);

        if ($options['string.utf8']) {
            $string = $this->encodeUtf8($string, $options);
        }

        $hexFormat = function ($matches) use ($options) {
            return sprintf($options['hex.capitalize'] ? '\x%02X' : '\x%02x', \ord($matches[0]));
        };

        return sprintf('"%s"', preg_replace_callback('/[^\x20-\x7E]/', $hexFormat, $string));
    }
private function getDoubleQuotedString($string, $options)
    {
        $string = strtr($string, [
            "\n" => '\n',
            "\r" => '\r',
            "\t" => '\t',
            '$' => '\$',
            '"' => '\"',
            '\\' => '\\\\',
        ]);

        if ($options['string.utf8']) {
            $string = $this->encodeUtf8($string, $options);
        }

        $hexFormat = function ($matches) use ($options) {
            return sprintf($options['hex.capitalize'] ? '\x%02X' : '\x%02x', \ord($matches[0]));
        };

        return sprintf('"%s"', preg_replace_callback('/[^\x20-\x7E]/', $hexFormat, $string));
    }
private function getDoubleQuotedString ( $ string , $ options ) { $ string = strtr ( $ string , [ "\n" => '\n' , "\r" => '\r' , "\t" => '\t' , '$' => '\$' , '"' => '\"' , '\\' => '\\\\' , ] ) ; if ( $ options [ 'string.utf8' ] ) { $ string = $ this -> encodeUtf8 ( $ string , $ options ) ; } $ hexFormat = function ( $ matches ) use ( $ options ) { return sprintf ( $ options [ 'hex.capitalize' ] ? '\x%02X' : '\x%02x' , \ ord ( $ matches [ 0 ] ) ) ; } ; return sprintf ( '"%s"' , preg_replace_callback ( '/[^\x20-\x7E]/' , $ hexFormat , $ string ) ) ; }
Returns the string wrapped in double quotes and all but print characters escaped.
@param string $string String to wrap and escape
@param array $options The string encoding options
@return string The string wrapped in double quotes and escape correctly
Returns the string wrapped in double quotes and all but print characters escaped .