1. Go to this page and download the library: Download rize/uri-template 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/ */
rize / uri-template example snippets
use Rize\UriTemplate;
$uri = new UriTemplate();
$uri->expand('/{username}/profile', ['username' => 'john']);
>> '/john/profile'
use Rize\UriTemplate;
$uri = new UriTemplate('https://api.twitter.com/{version}', ['version' => 1.1]);
$uri->expand('/statuses/show/{id}.json', ['id' => '210462857140252672']);
>> https://api.twitter.com/1.1/statuses/show/210462857140252672.json
use Rize\UriTemplate;
$uri = new UriTemplate('https://api.twitter.com/{version}', ['version' => 1.1]);
$params = $uri->extract('/search/{term:1}/{term}/{?q*,limit}', '/search/j/john/?q=a&q=b&limit=10');
>> print_r($params);
(
[term:1] => j
[term] => john
[q] => Array
(
[0] => a
[1] => b
)
[limit] => 10
)
use Rize\UriTemplate;
$uri = new UriTemplate();
$uri->extract($template, $uri, $strict = false)
use Rize\UriTemplate;
$uri = new UriTemplate();
$params = $uri->extract('/{?a,b}', '/?a=1')
>> print_r($params);
(
[a] => 1
[b] => null
)
use Rize\UriTemplate;
$uri = new UriTemplate();
// Note that variable `b` is absent in uri
$params = $uri->extract('/{?a,b}', '/?a=1', true);
>>> null
// Now we give `b` some value
$params = $uri->extract('/{?a,b}', '/?a=1&b=2', true);
>>> print_r($params)
(
[a] => 1
[b] => 2
)