Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added examples

  • Loading branch information...
commit f2852acf846d99fe87a3c063809424e7dca5db34 1 parent a418a61
Ioseb Dzmanashvili authored
View
63 examples/form_style_query_continuation.php
@@ -0,0 +1,63 @@
+<?php
+
+$data = array(
+ 'count' => array("one", "two", "three"),
+ 'dom' => array("example", "com"),
+ 'dub' => "me/too",
+ 'hello' => "Hello World!",
+ 'half' => "50%",
+ 'var' => "value",
+ 'who' => "fred",
+ 'base' => "http://example.com/home/",
+ 'path' => "/foo/bar",
+ 'list' => array("red", "green", "blue"),
+ 'keys' => array(
+ "semi" => ";",
+ "dot" => ".",
+ "comma" => ",",
+ ),
+ 'v' => "6",
+ 'x' => "1024",
+ 'y' => "768",
+ 'empty' => "",
+ 'empty_keys' => array(),
+ 'undef' => null,
+);
+
+$templates = array(
+ "{&who}",
+ "{&half}",
+ "?fixed=yes{&x}",
+ "{&x,y,empty}",
+ "{&x,y,undef}",
+ "{&var:3}",
+ "{&list}",
+ "{&list*}",
+ "{&keys}",
+ "{&keys*}"
+);
+
+$uris = array();
+
+foreach ($templates as $template) {
+ $uris[$template] = uri_template($template, $data);
+}
+
+var_export($uris);
+
+/* Result */
+/*
+array(
+ "{&who}" => "&who=fred",
+ "{&half}" => "&half=50%25",
+ "?fixed=yes{&x}" => "?fixed=yes&x=1024",
+ "{&x,y,empty}" => "&x=1024&y=768&empty=",
+ "{&x,y,undef}" => "&x=1024&y=768",
+ "{&var:3}" => "&var=val",
+ "{&list}" => "&list=red,green,blue",
+ "{&list*}" => "&list=red&list=green&list=blue",
+ "{&keys}" => "&keys=semi,%3B,dot,.,comma,%2C",
+ "{&keys*}" => "&semi=%3B&dot=.&comma=%2C"
+)
+*/
+?>
View
63 examples/form_style_query_expansion.php
@@ -0,0 +1,63 @@
+<?php
+
+$data = array(
+ 'count' => array("one", "two", "three"),
+ 'dom' => array("example", "com"),
+ 'dub' => "me/too",
+ 'hello' => "Hello World!",
+ 'half' => "50%",
+ 'var' => "value",
+ 'who' => "fred",
+ 'base' => "http://example.com/home/",
+ 'path' => "/foo/bar",
+ 'list' => array("red", "green", "blue"),
+ 'keys' => array(
+ "semi" => ";",
+ "dot" => ".",
+ "comma" => ",",
+ ),
+ 'v' => "6",
+ 'x' => "1024",
+ 'y' => "768",
+ 'empty' => "",
+ 'empty_keys' => array(),
+ 'undef' => null,
+);
+
+$templates = array(
+ "{?who}",
+ "{?half}",
+ "{?x,y}",
+ "{?x,y,empty}",
+ "{?x,y,undef}",
+ "{?var:3}",
+ "{?list}",
+ "{?list*}",
+ "{?keys}",
+ "{?keys*}"
+);
+
+$uris = array();
+
+foreach ($templates as $template) {
+ $uris[$template] = uri_template($template, $data);
+}
+
+var_export($uris);
+
+/* Result */
+/*
+array(
+ "{?who}" => "?who=fred",
+ "{?half}" => "?half=50%25",
+ "{?x,y}" => "?x=1024&y=768",
+ "{?x,y,empty}" => "?x=1024&y=768&empty=",
+ "{?x,y,undef}" => "?x=1024&y=768",
+ "{?var:3}" => "?var=val",
+ "{?list}" => "?list=red,green,blue",
+ "{?list*}" => "?list=red&list=green&list=blue",
+ "{?keys}" => "?keys=semi,%3B,dot,.,comma,%2C",
+ "{?keys*}" => "?semi=%3B&dot=.&comma=%2C"
+)
+*/
+?>
View
67 examples/fragment_expansion.php
@@ -0,0 +1,67 @@
+<?php
+
+$data = array(
+ 'count' => array("one", "two", "three"),
+ 'dom' => array("example", "com"),
+ 'dub' => "me/too",
+ 'hello' => "Hello World!",
+ 'half' => "50%",
+ 'var' => "value",
+ 'who' => "fred",
+ 'base' => "http://example.com/home/",
+ 'path' => "/foo/bar",
+ 'list' => array("red", "green", "blue"),
+ 'keys' => array(
+ "semi" => ";",
+ "dot" => ".",
+ "comma" => ",",
+ ),
+ 'v' => "6",
+ 'x' => "1024",
+ 'y' => "768",
+ 'empty' => "",
+ 'empty_keys' => array(),
+ 'undef' => null,
+);
+
+$templates = array(
+ "{#var}",
+ "{#hello}",
+ "{#half}",
+ "foo{#empty}",
+ "foo{#undef}",
+ "{#x,hello,y}",
+ "{#path,x}/here",
+ "{#path:6}/here",
+ "{#list}",
+ "{#list*}",
+ "{#keys}",
+ "{#keys*}"
+);
+
+$uris = array();
+
+foreach ($templates as $template) {
+ $uris[$template] = uri_template($template, $data);
+}
+
+var_export($uris);
+
+/* Result */
+/*
+array(
+ "{#var}" => "#value",
+ "{#hello}" => "#Hello%20World!",
+ "{#half}" => "#50%25",
+ "foo{#empty}" => "foo#",
+ "foo{#undef}" => "foo",
+ "{#x,hello,y}" => "#1024,Hello%20World!,768",
+ "{#path,x}/here" => "#/foo/bar,1024/here",
+ "{#path:6}/here" => "#/foo/b/here",
+ "{#list}" => "#red,green,blue",
+ "{#list*}" => "#red,green,blue",
+ "{#keys}" => "#semi,;,dot,.,comma,,",
+ "{#keys*}" => "#semi=;,dot=.,comma=,"
+)
+*/
+?>
View
71 examples/label_expansion_with_dot_prefix.php
@@ -0,0 +1,71 @@
+<?php
+
+$data = array(
+ 'count' => array("one", "two", "three"),
+ 'dom' => array("example", "com"),
+ 'dub' => "me/too",
+ 'hello' => "Hello World!",
+ 'half' => "50%",
+ 'var' => "value",
+ 'who' => "fred",
+ 'base' => "http://example.com/home/",
+ 'path' => "/foo/bar",
+ 'list' => array("red", "green", "blue"),
+ 'keys' => array(
+ "semi" => ";",
+ "dot" => ".",
+ "comma" => ",",
+ ),
+ 'v' => "6",
+ 'x' => "1024",
+ 'y' => "768",
+ 'empty' => "",
+ 'empty_keys' => array(),
+ 'undef' => null,
+);
+
+$templates = array(
+ "{.who}",
+ "{.who,who}",
+ "{.half,who}",
+ "www{.dom*}",
+ "X{.var}",
+ "X{.empty}",
+ "X{.undef}",
+ "X{.var:3}",
+ "X{.list}",
+ "X{.list*}",
+ "X{.keys}",
+ "X{.keys*}",
+ "X{.empty_keys}",
+ "X{.empty_keys*}"
+);
+
+$uris = array();
+
+foreach ($templates as $template) {
+ $uris[$template] = uri_template($template, $data);
+}
+
+var_export($uris);
+
+/* Result */
+/*
+array(
+ "{.who}" => ".fred",
+ "{.who,who}" => ".fred.fred",
+ "{.half,who}" => ".50%25.fred",
+ "www{.dom*}" => "www.example.com",
+ "X{.var}" => "X.value",
+ "X{.empty}" => "X.",
+ "X{.undef}" => "X",
+ "X{.var:3}" => "X.val",
+ "X{.list}" => "X.red,green,blue",
+ "X{.list*}" => "X.red.green.blue",
+ "X{.keys}" => "X.semi,%3B,dot,.,comma,%2C",
+ "X{.keys*}" => "X.semi=%3B.dot=..comma=%2C",
+ "X{.empty_keys}" => "X",
+ "X{.empty_keys*}" => "X"
+)
+*/
+?>
View
71 examples/path_segment_expansion.php
@@ -0,0 +1,71 @@
+<?php
+
+$data = array(
+ 'count' => array("one", "two", "three"),
+ 'dom' => array("example", "com"),
+ 'dub' => "me/too",
+ 'hello' => "Hello World!",
+ 'half' => "50%",
+ 'var' => "value",
+ 'who' => "fred",
+ 'base' => "http://example.com/home/",
+ 'path' => "/foo/bar",
+ 'list' => array("red", "green", "blue"),
+ 'keys' => array(
+ "semi" => ";",
+ "dot" => ".",
+ "comma" => ",",
+ ),
+ 'v' => "6",
+ 'x' => "1024",
+ 'y' => "768",
+ 'empty' => "",
+ 'empty_keys' => array(),
+ 'undef' => null,
+);
+
+$templates = array(
+ "{/who}",
+ "{/who,who}",
+ "{/half,who}",
+ "{/who,dub}",
+ "{/var}",
+ "{/var,empty}",
+ "{/var,undef}",
+ "{/var,x}/here",
+ "{/var:1,var}",
+ "{/list}",
+ "{/list*}",
+ "{/list*,path:4}",
+ "{/keys}",
+ "{/keys*}"
+);
+
+$uris = array();
+
+foreach ($templates as $template) {
+ $uris[$template] = uri_template($template, $data);
+}
+
+var_export($uris);
+
+/* Result */
+/*
+array(
+ "{/who}" => "/fred",
+ "{/who,who}" => "/fred/fred",
+ "{/half,who}" => "/50%25/fred",
+ "{/who,dub}" => "/fred/me%2Ftoo",
+ "{/var}" => "/value",
+ "{/var,empty}" => "/value/",
+ "{/var,undef}" => "/value",
+ "{/var,x}/here" => "/value/1024/here",
+ "{/var:1,var}" => "/v/value",
+ "{/list}" => "/red,green,blue",
+ "{/list*}" => "/red/green/blue",
+ "{/list*,path:4}" => "/red/green/blue/%2Ffoo",
+ "{/keys}" => "/semi,%3B,dot,.,comma,%2C",
+ "{/keys*}" => "/semi=%3B/dot=./comma=%2C"
+)
+*/
+?>
View
69 examples/path_style_parameter_expansion.php
@@ -0,0 +1,69 @@
+<?php
+
+$data = array(
+ 'count' => array("one", "two", "three"),
+ 'dom' => array("example", "com"),
+ 'dub' => "me/too",
+ 'hello' => "Hello World!",
+ 'half' => "50%",
+ 'var' => "value",
+ 'who' => "fred",
+ 'base' => "http://example.com/home/",
+ 'path' => "/foo/bar",
+ 'list' => array("red", "green", "blue"),
+ 'keys' => array(
+ "semi" => ";",
+ "dot" => ".",
+ "comma" => ",",
+ ),
+ 'v' => "6",
+ 'x' => "1024",
+ 'y' => "768",
+ 'empty' => "",
+ 'empty_keys' => array(),
+ 'undef' => null,
+);
+
+$templates = array(
+ "{;who}",
+ "{;half}",
+ "{;empty}",
+ "{;v,empty,who}",
+ "{;v,bar,who}",
+ "{;x,y}",
+ "{;x,y,empty}",
+ "{;x,y,undef}",
+ "{;hello:5}",
+ "{;list}",
+ "{;list*}",
+ "{;keys}",
+ "{;keys*}"
+);
+
+$uris = array();
+
+foreach ($templates as $template) {
+ $uris[$template] = uri_template($template, $data);
+}
+
+var_export($uris);
+
+/* Result */
+/*
+array(
+ "{;who}" => ";who=fred",
+ "{;half}" => ";half=50%25",
+ "{;empty}" => ";empty",
+ "{;v,empty,who}" => ";v=6;empty;who=fred",
+ "{;v,bar,who}" => ";v=6;who=fred",
+ "{;x,y}" => ";x=1024;y=768",
+ "{;x,y,empty}" => ";x=1024;y=768;empty",
+ "{;x,y,undef}" => ";x=1024;y=768",
+ "{;hello:5}" => ";hello=Hello",
+ "{;list}" => ";list=red,green,blue",
+ "{;list*}" => ";list=red;list=green;list=blue",
+ "{;keys}" => ";keys=semi,%3B,dot,.,comma,%2C",
+ "{;keys*}" => ";semi=%3B;dot=.;comma=%2C"
+)
+*/
+?>
View
77 examples/reserved_expansion.php
@@ -0,0 +1,77 @@
+<?php
+
+$data = array(
+ 'count' => array("one", "two", "three"),
+ 'dom' => array("example", "com"),
+ 'dub' => "me/too",
+ 'hello' => "Hello World!",
+ 'half' => "50%",
+ 'var' => "value",
+ 'who' => "fred",
+ 'base' => "http://example.com/home/",
+ 'path' => "/foo/bar",
+ 'list' => array("red", "green", "blue"),
+ 'keys' => array(
+ "semi" => ";",
+ "dot" => ".",
+ "comma" => ",",
+ ),
+ 'v' => "6",
+ 'x' => "1024",
+ 'y' => "768",
+ 'empty' => "",
+ 'empty_keys' => array(),
+ 'undef' => null,
+);
+
+$templates = array(
+ "{+var}",
+ "{+hello}",
+ "{+half}",
+ "{base}index",
+ "{+base}index",
+ "O{+empty}X",
+ "O{+undef}X",
+ "{+path}/here",
+ "here?ref={+path}",
+ "up{+path}{var}/here",
+ "{+x,hello,y}",
+ "{+path,x}/here",
+ "{+path:6}/here",
+ "{+list}",
+ "{+list*}",
+ "{+keys}",
+ "{+keys*}"
+);
+
+$uris = array();
+
+foreach ($templates as $template) {
+ $uris[$template] = uri_template($template, $data);
+}
+
+var_export($uris);
+
+/* Result */
+/*
+array (
+ '{+var}' => 'value',
+ '{+hello}' => 'Hello%20World!',
+ '{+half}' => '50%25',
+ '{base}index' => 'http%3A%2F%2Fexample.com%2Fhome%2Findex',
+ '{+base}index' => 'http://example.com/home/index',
+ 'O{+empty}X' => 'OX',
+ 'O{+undef}X' => 'OX',
+ '{+path}/here' => '/foo/bar/here',
+ 'here?ref={+path}' => 'here?ref=/foo/bar',
+ 'up{+path}{var}/here' => 'up/foo/barvalue/here',
+ '{+x,hello,y}' => '1024,Hello%20World!,768',
+ '{+path,x}/here' => '/foo/bar,1024/here',
+ '{+path:6}/here' => '/foo/b/here',
+ '{+list}' => 'red,green,blue',
+ '{+list*}' => 'red,green,blue',
+ '{+keys}' => 'semi,;,dot,.,comma,,',
+ '{+keys*}' => 'semi=;,dot=.,comma=,',
+)
+*/
+?>
View
75 examples/simple_string_expansion.php
@@ -0,0 +1,75 @@
+<?php
+
+$data = array(
+ 'count' => array("one", "two", "three"),
+ 'dom' => array("example", "com"),
+ 'dub' => "me/too",
+ 'hello' => "Hello World!",
+ 'half' => "50%",
+ 'var' => "value",
+ 'who' => "fred",
+ 'base' => "http://example.com/home/",
+ 'path' => "/foo/bar",
+ 'list' => array("red", "green", "blue"),
+ 'keys' => array(
+ "semi" => ";",
+ "dot" => ".",
+ "comma" => ",",
+ ),
+ 'v' => "6",
+ 'x' => "1024",
+ 'y' => "768",
+ 'empty' => "",
+ 'empty_keys' => array(),
+ 'undef' => null,
+);
+
+$templates = array(
+ "{var}",
+ "{hello}",
+ "{half}",
+ "O{empty}X",
+ "O{undef}X",
+ "{x,y}",
+ "{x,hello,y}",
+ "?{x,empty}",
+ "?{x,undef}",
+ "?{undef,y}",
+ "{var:3}",
+ "{var:30}",
+ "{list}",
+ "{list*}",
+ "{keys}",
+ "{keys*}"
+);
+
+$uris = array();
+
+foreach ($templates as $template) {
+ $uris[$template] = uri_template($template, $data);
+}
+
+var_export($uris);
+
+/* Result */
+/*
+array (
+ '{var}' => 'value',
+ '{hello}' => 'Hello%20World%21',
+ '{half}' => '50%25',
+ 'O{empty}X' => 'OX',
+ 'O{undef}X' => 'OX',
+ '{x,y}' => '1024,768',
+ '{x,hello,y}' => '1024,Hello%20World%21,768',
+ '?{x,empty}' => '?1024,',
+ '?{x,undef}' => '?1024',
+ '?{undef,y}' => '?768',
+ '{var:3}' => 'val',
+ '{var:30}' => 'value',
+ '{list}' => 'red,green,blue',
+ '{list*}' => 'red,green,blue',
+ '{keys}' => 'semi,%3B,dot,.,comma,%2C',
+ '{keys*}' => 'semi=%3B,dot=.,comma=%2C',
+)
+*/
+?>
View
61 examples/variable_expansion.php
@@ -0,0 +1,61 @@
+<?php
+
+$data = array(
+ 'count' => array("one", "two", "three"),
+ 'dom' => array("example", "com"),
+ 'dub' => "me/too",
+ 'hello' => "Hello World!",
+ 'half' => "50%",
+ 'var' => "value",
+ 'who' => "fred",
+ 'base' => "http://example.com/home/",
+ 'path' => "/foo/bar",
+ 'list' => array("red", "green", "blue"),
+ 'keys' => array(
+ "semi" => ";",
+ "dot" => ".",
+ "comma" => ",",
+ ),
+ 'v' => "6",
+ 'x' => "1024",
+ 'y' => "768",
+ 'empty' => "",
+ 'empty_keys' => array(),
+ 'undef' => null,
+);
+
+$templates = array(
+ '{count}',
+ '{count*}',
+ '{/count}',
+ '{/count*}',
+ '{;count}',
+ '{;count*}',
+ '{?count}',
+ '{?count*}',
+ '{&count*}',
+);
+
+$uris = array();
+
+foreach ($templates as $template) {
+ $uris[$template] = uri_template($template, $data);
+}
+
+var_export($uris);
+
+/* Result */
+/*
+array (
+ '{count}' => 'one,two,three',
+ '{count*}' => 'one,two,three',
+ '{/count}' => '/one,two,three',
+ '{/count*}' => '/one/two/three',
+ '{;count}' => ';count=one,two,three',
+ '{;count*}' => ';count=one;count=two;count=three',
+ '{?count}' => '?count=one,two,three',
+ '{?count*}' => '?count=one&count=two&count=three',
+ '{&count*}' => '&count=one&count=two&count=three',
+)
+*/
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.