PHP code example of jdwx / quote

1. Go to this page and download the library: Download jdwx/quote library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jdwx / quote example snippets



$parser = new Parser(
    hardQuote: QuoteOperator::simple(),
    delimiter: DelimiterOperator::whitespace(),
);

var_dump( iterator_to_array( $parser( 'The "quick brown fox" jumps \'over the\' lazy dog.' ) ) );

array(6) {
  [0] =>
  string(3) "The"
  [1] =>
  string(15) "quick brown fox"
  [2] =>
  string(5) "jumps"
  [3] =>
  string(8) "over the"
  [4] =>
  string(4) "lazy"
  [5] =>
  string(4) "dog."
}

$fnVars = new Variables( [
    'foo' => 'quick',
    'fox' => 'nope',
] );
$parser = new Parser(
    comment: QuoteOperator::cComment(),
    hardQuote: QuoteOperator::single(),
    softQuote: QuoteOperator::double(),
    strongCallback: QuoteOperator::backtick(),
    weakCallback: QuoteOperator::varCurly(),
    openCallback: OpenEndedOperator::var(),
    escape: new MultiOperator( [ new HexEscape(), new ControlCharEscape() ] ),
    delimiter: ConsolidatedDelimiterOperator::whitespace(),

    # These are the functions used by callback operators.
    fnStrong: fn( string $st ) : string => strtolower( $st ),
    fnWeak: $fnVars,
    fnOpen: $fnVars
);

$st = 'The/* slow! */ $foo    \'brown $fox\' "jumps over" \\x74he `LAZY` dog.\n';
echo Segment::mergeValues( $parser->parse( $st ) );