PHP code example of artklen / ub

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

    

artklen / ub example snippets


$ub = new UB($path, $fields, $values);

print new UB(
    path:   '/catalog/',
    fields: ['price', 'producer_id'],
    values: [
                'producer_id' => [1, 2],
                'sort' => 'popularity',
                'price' => [
                    'max' => 20000,
                ],
            ],
);

new UB(
    path:   strtok($_SERVER['REQUEST_URI'], '?'),
    values: $_GET,
)

function ub_from_url(string $url): UB
{
    parse_str(parse_url($url, PHP_URL_QUERY), $values);
    return new UB(
        path:   parse_url($url, PHP_URL_PATH),
        values: $values,
    );
}

$ub = ub_from_url('/catalog/?price%5Bmax%5D=20000&producer_id%5B%5D=1&producer_id%5B%5D=2&sort=popularity');
print $ub->getPath() . "\n";
print json_encode($ub->getAllValues()) . "\n";