Пример #1
0
function discover($target_url)
{
    $webmention_endpoint = NULL;
    $response_body = http\request("GET {$target_url}", array(), array(), $response_headers);
    if (isset($response_headers['link'])) {
        $links = link_header\parse($response_headers['link']);
        if (isset($links['http://webmention.org/'])) {
            $webmention_endpoint = $links['http://webmention.org/'][0]['uri'];
        } elseif (isset($links['webmention'])) {
            $webmention_endpoint = $links['webmention'][0]['uri'];
        }
    }
    if (!is_null($webmention_endpoint)) {
        return $webmention_endpoint;
    } elseif (preg_match('#<link href="([^"]+)" rel="http://webmention.org/" ?/?>#i', $response_body, $matches) or preg_match('#<link rel="http://webmention.org/" href="([^"]+)" ?/?>#i', $response_body, $matches)) {
        return $matches[1];
    }
}
Пример #2
0
		)

	[http://example.net/relation/other] => Array
		(
			[0] => Array
				(
					[uri] => http://example.org/
				)

		)

)
*/
// Examples that simple regex based parsers fail on:
print_r(link_header\parse('<http://example.com/TheBook/chapter1>; rel="previous"; title="start, index"'));
/*
Array
(
	[previous] => Array
		(
			[0] => Array
				(
					[uri] => http://example.com/TheBook/chapter1
					[title] => start, index
				)

		)

)
*/