How to get Link Headers (for pagination) from API using PHP cURL How to get Link Headers (for pagination) from API using PHP cURL curl curl

How to get Link Headers (for pagination) from API using PHP cURL


Ok I got there - In order to preserve the URLs in the headers, contained within angle brackets, I needed to URL encode the output from curl_exec:

$rest = rawurlencode(curl_exec($ch));

Example output:

Link%3A%20%3Chttps%3A%2F%2Fapi.mendeley.com%2Fdatasets%3Fmarker%3Db6ea8b2a-c4fa-4a84-989a-66cf7801abbf%26limit%3D3%26sort%3Dpublish_date%26fields%3Dresults.id%26reverse%3Dfalse%26order%3Ddesc


having code like this:

$content = <<<HTMLLink: <meta.rdf>; rel=metaContent.HTML;print_r($content);

shows in browser exactly:

Link: ; rel=meta Content.

because things within angle brackets are considered to be tags and are not rendered. If you use "crtl+u" shortcut to view sourcecode, you will see:

Link: <meta.rdf>; rel=metaContent.

And this means that everything is working fine, and you have everything you need.

I bet that it's your case.