PHP code example of graviton / link-header-rel-parser

1. Go to this page and download the library: Download graviton/link-header-rel-parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

graviton / link-header-rel-parser example snippets


$header = '<http://localhost/service/self>; rel="self", '<http://localhost/service/next>; rel="next"';
$linkHeader = LinkHeader::fromString($header);

$selfUrl = $linkHeader->getRel('self')->getUri(); // will output 'http://localhost/service/self'

$header = new LinkHeader();
$header->add(new LinkHeaderItem('http://localhost?limit(10,10)', 'self'));
$header->add(new LinkHeaderItem('http://localhost?limit(10,30)', 'next'));
$header->add(new LinkHeaderItem('http://localhost?limit(10,0)', 'prev'));

echo (string) $header;

$header = '<http://localhost/service/self>; rel="self", '<http://localhost/service/next>; rel="next"';
$linkHeader = LinkHeader::fromString($header);

$linkHeader->add(new LinkHeaderItem('http://localhost?limit(10,10)', 'prev'));
$linkHeader->removeRel('next');
$header->getRel('self')->setUri('http://newhost');

echo (string) $header;

<http://localhost?limit(10,10)>; rel="self", <http://localhost?limit(10,30)>; rel="next", <http://localhost?limit(10,0)>; rel="prev"

<http://newhost>; rel="self", <http://localhost?limit(10,10)>; rel="prev"