PHP code example of vertilia / parser

1. Go to this page and download the library: Download vertilia/parser 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/ */

    

vertilia / parser example snippets




$parser = new OpenApiParser();

// simple pattern

$pattern = $parser->getRegex('/users/{id}');
echo $pattern;
// outputs: #^/users/(?P<id>[^:/?\#\[\]@!$&'()*+;=]+)$#

$result = preg_match($pattern, '/users/123,234', $matches);
echo $matches['id'];
// outputs: 123,234

// complex pattern

$pattern = $parser->getRegex(
    '/users{id}/friends{friend}',
    [
        'id' => ['style' => 'matrix'],
        'friend' => ['style' => 'label', 'explode' => true],
    ]
);

preg_match(
    $pattern,
    '/users;id=3,4,5/friends.6.7.8',
    $matches
);
echo $matches['id'], ' - ', $matches['friend'];
// outputs: ;id=3,4,5 - .6.7.8