Download the PHP package dcarbone/curl-file-header-extractor without Composer
On this page you can find all versions of the php package dcarbone/curl-file-header-extractor. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package curl-file-header-extractor
curl-header-extractor
Utility to extract headers from PHP CURL request.
Installation
While it is advisable to use Composer, this lib is simple enough to be used without it.
Composer Require entry:
Usage
There are 3 methods available:
getHeaderAndBody
This method accepts a single argument that may be:
- Full path to the file
- File resource created with fopen with at least read permissions.
- String of response data
The response will be an array with the following structure:
Example:
where $headers
will be an array of headers, or NULL if no headers were found,
and $body
will be the entire contents of the body.
Note:
This method CAN be very expensive to use if you are working with particularly large responses, as the end result will be the entire contents of the file loaded into memory.
If you wish to extract JUST the headers, the below methods might serve you better.
extractHeadersAndBodyStartOffset
This method will return an array with the following structure:
Example:
If no headers were seen in the file, $headers
in the above example will be NULL and the byte offset
will be 0.
removeHeadersAndMoveFile
This method will strip the file of the headers, copy the body to a new file, and then delete the old file.
Example:
If you executed the extractHeadersAndBodyStartOffset method already, you may pass in the body start offset integer in as the 3rd argument.
Invoking
To make this class easier to work with as a "helper", it implements the PHP magic method __invoke (you can see the implementation here).
This allows you to do something like this:
You can, of course, access the other methods as you normally would any static method:
All versions of curl-file-header-extractor with dependencies
ext-mbstring Version *