PHP code example of frizz925 / curl-parser

1. Go to this page and download the library: Download frizz925/curl-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/ */

    

frizz925 / curl-parser example snippets





 <<<EOF
curl 'https://api.github.com/' -H 'Pragma: no-cache' -H 'DNT: 1' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.9' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' -H 'Cache-Control: no-cache' -H 'Connection: keep-alive' --compressed
EOF;
$parsed = CurlParser\Parser::parse($curl);
$uri = $parsed->getUri();
echo $uri;
// 'https://api.github.com/'
echo $uri instanceof Psr\Http\Message\UriInterface;
// true
echo $uri->getHost();
// 'api.github.com'

echo $parsed->getMethod();
// 'GET'
echo $parsed->getBody();
// ''
var_dump($parsed->getHeaders());
// ['Accept-Encoding' => ['gzip', 'deflate', 'br'], DNT' => ['1'], ...]

$req = $parsed->toRequest();
echo $req instanceof Psr\Http\Message\RequestInterface;
// true