require_once "URI/Template.php";
$values = array("a" => "foo", "b" => "bar", "data" => "10,20,30",
"points" => array(10, 20, 30), "list0" => array(),
"str0" => "", "reserved" => ":/?#[]@!$&'()*+,;=",
"a_b" => "baz");
$t = new URI_Template("/{-append|/|a}{-opt|data|points}{-neg|@|a}{-prefix|#|b}");
echo $t->substitute($values); /* /foo/data#bar */
$t = new URI_Template("relative/{reserved}/");
echo $t->substitute($values); /* relative/%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D/ */
$t = new URI_Template("http://example.org/{foo=%25}/");
echo $t->substitute($values); /* http://example.org/%25/ */
$t = new URI_Template("http://example.org/?{-join|&|a,data}");
echo $t->substitute($values); /* http://example.org/?a=foo&data=10%2C20%2C30 */
$t = new URI_Template("http://example.org/?d={-listjoin|,|points}&{-join|&|a,b}");
echo $t->substitute($values); /* http://example.org/?d=10,20,30&a=foo&b=bar */
$t = new URI_Template("http://example.org/?d={-listjoin|,|list0}&{-join|&|foo}");
echo $t->substitute(array()); /* http://example.org/?d=& */
$t = new URI_Template("http://example.org/?d={-listjoin|&d=|points}");
echo $t->substitute($values); /* http://example.org/?d=10&d=20&d=30 */
$t = new URI_Template("http://example.org/{a}{b}/{a_b}");
echo $t->substitute($values); /* http://example.org/foobar/baz */
$t = new URI_Template("http://example.org/{a}{-prefix|/-/|a}/");
echo $t->substitute($values); /* http://example.org/foo/-/foo/ */ |