flush docs
[mdref/mdref-http] / http / Params / : Examples.md
1 # http\Params Examples
2
3 ## RFC5987 example:
4
5 <?php
6
7 $u = urlencode("ü");
8 $s = urlencode("ß");
9
10 $t = "p1*=utf-8'de's$u$s,p2*=utf-8''hei$s;a1*=utf-8''a$s;a2*=utf-8''e$s;a3=no,p3=not";
11 $p = new http\Params($t);
12
13 var_dump($p->params, $p->toString());
14
15 ?>
16
17 ### Yields:
18
19 array(3) {
20 ["p1"]=>
21 array(2) {
22 ["*rfc5987*"]=>
23 array(1) {
24 ["de"]=>
25 string(5) "süß"
26 }
27 ["arguments"]=>
28 array(0) {
29 }
30 }
31 ["p2"]=>
32 array(2) {
33 ["*rfc5987*"]=>
34 array(1) {
35 [""]=>
36 string(5) "heiß"
37 }
38 ["arguments"]=>
39 array(2) {
40 ["*rfc5987*"]=>
41 array(2) {
42 ["a1"]=>
43 array(1) {
44 [""]=>
45 string(3) "aß"
46 }
47 ["a2"]=>
48 array(1) {
49 [""]=>
50 string(3) "eß"
51 }
52 }
53 ["a3"]=>
54 string(2) "no"
55 }
56 }
57 ["p3"]=>
58 array(2) {
59 ["value"]=>
60 string(3) "not"
61 ["arguments"]=>
62 array(0) {
63 }
64 }
65 }
66 string(98) "p1*=utf-8'de's%C3%BC%C3%9F,p2*=utf-8''hei%C3%9F;a1*=utf-8''a%C3%9F;a2*=utf-8''e%C3%9F;a3=no,p3=not"
67
68 ## Web Linking Example:
69
70 $link = <<<EOF
71 Link: </TheBook/chapter2>;
72 rel="previous"; title*=UTF-8'de'letztes%20Kapitel,
73 </TheBook/chapter4>;
74 rel="next"; title*=UTF-8'de'n%c3%a4chstes%20Kapitel
75 EOF;
76
77 $p = current(http\Header::parse($link, "http\\Header"))->getParams(
78 http\Params::DEF_PARAM_SEP,
79 http\Params::DEF_ARG_SEP,
80 http\Params::DEF_VAL_SEP,
81 http\Params::PARSE_RFC5988 | http\Params::PARSE_ESCAPED
82 );
83
84 var_dump($p->params);
85 var_dump((string)$p);
86
87 ### Yields:
88
89 array(2) {
90 ["/TheBook/chapter2"]=>
91 array(2) {
92 ["value"]=>
93 bool(true)
94 ["arguments"]=>
95 array(2) {
96 ["rel"]=>
97 string(8) "previous"
98 ["*rfc5987*"]=>
99 array(1) {
100 ["title"]=>
101 array(1) {
102 ["de"]=>
103 string(15) "letztes Kapitel"
104 }
105 }
106 }
107 }
108 ["/TheBook/chapter4"]=>
109 array(2) {
110 ["value"]=>
111 bool(true)
112 ["arguments"]=>
113 array(2) {
114 ["rel"]=>
115 string(4) "next"
116 ["*rfc5987*"]=>
117 array(1) {
118 ["title"]=>
119 array(1) {
120 ["de"]=>
121 string(17) "nächstes Kapitel"
122 }
123 }
124 }
125 }
126 }
127 string(139) "</TheBook/chapter2>;rel="previous";title*=utf-8'de'letztes%20Kapitel,</TheBook/chapter4>;rel="next";title*=utf-8'de'n%C3%A4chstes%20Kapitel"