typo, parameter and type fixes
[mdref/mdref-http] / http / Env / negotiateContentType.md
1 # static string http\Env::negotiateContentType(array $supported[, array &$result])
2
3 Negotiate the client's preferred MIME content type.
4
5 > ***NOTE:***
6 > The first element of $supported content types serves as a default if no content-type matches.
7
8 ## Params:
9
10 * array $supported
11 List of supported MIME content types.
12 * Optional array &$result
13 Out parameter recording negotiation results.
14
15 ## Returns:
16
17 * NULL, if negotiation fails.
18 * string, the negotiated content type.
19
20 ## Example:
21
22 A client indicates his accepted MIME content types by sending an Accept
23 header. The static http\Env class provides a facility to negotiate the
24 client's preferred content type:
25
26 <?php
27 $_SERVER["HTTP_ACCEPT"] = implode(",", array(
28 "text/html",
29 "text/plain",
30 "text/*;q=0.9",
31 "*/*;q=0.1",
32 "application/xml;q=0"
33 ));
34 $supported = array(
35 "text/html",
36 "text/plain",
37 "application/json",
38 "application/xml"
39 );
40 $preferred = http\Env::negotiateContentType($supported, $ranking);
41 var_dump($preferred, $ranking);
42 ?>
43
44 Running this script should give the following output:
45
46 string(9) "text/html"
47 array(3) {
48 'text/html' =>
49 float(0.99)
50 'text/plain' =>
51 float(0.98)
52 'application/json' =>
53 float(0.1)
54 }
55
56
57