PEAR's HTTP2 package got Web Linking (RFC 5988) support in version 1.1.0.
Parsing HTTP Link: header values is now easy:
<?php require_once 'HTTP2.php'; //Link headers that we got from somewhere, e.g. // HTTP_Request2_Response::getHeader('link') $link = '<http://pear.php.net/webmention.php>; rel="webmention"'; $http = new HTTP2(); $links = $http->parseLinks($link); var_dump($links); ?>
It will give you the following output:
array(1) { [0] => array(2) { '_uri' => string(34) "http://pear.php.net/webmention.php" 'rel' => array(1) { [0] => string(10) "webmention" } } }
HTTP link headers are used to express relations of the resource to other URIs, e.g. copyright info or prev/next links of a paged result.
Apart from the URI, link headers may contain a number of attributes (parameters) . Here are some of them:
- rel
- Relation of the URI to the current resource, e.g. "copyright", "index", "next" or "stylesheet". See the list of registered relations .
- type
- MIME type of the URI. Can be used to link to alternate formats of the current resource.
- title
- Human readable title of the link
I implemented the HTTP2::parseLinks() method because web linking is used by WebMention to detect the URL of the linkback server.