tiagohillebrandt/php-parse-link-header

解析 HTTP Link 头部并返回一个数组中的值。

1.0.4 2020-04-15 22:58 UTC

This package is auto-updated.

Last update: 2024-09-16 08:25:21 UTC


README

解析 HTTP Link 头部并返回一个数组。

使用 Composer 安装

$ composer require tiagohillebrandt/php-parse-link-header

使用方法

$headers = [
    'Link' => '<https://api.github.com/organizations/xyz/repos?page=2>; rel="next", <https://api.github.com/organizations/xyz/repos?page=4>; rel="last"',
];

$links = ( new TiagoHillebrandt\ParseLinkHeader( $headers['Link'] ) )->toArray();

print_r( $links );

上述示例将输出

Array
(
    [next] => Array
        (
            [link] => https://api.github.com/organizations/xyz/repos?page=2
            [page] => 2
        )

    [last] => Array
        (
            [link] => https://api.github.com/organizations/xyz/repos?page=4
            [page] => 4
        )

)