PHP code example of vircom / http-parser

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

    

vircom / http-parser example snippets




use VirCom\HttpParser\HttpParserFactory;

$request = "POST /cgi-bin/process.cgi HTTP/0.9\r\n"
 . "User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)\r\n"
 . "\r\n"
 . "exampleName1=exampleValue1&exampleName2=exampleValue2";

$parser = (new HttpParserFactory())->createRequestParser();
$result = $parser->parse($request);


VirCom\HttpParser\HttpParserFactory;

$response = "HTTP/1.1 200 OK\r\n"
 . "Content-Type: application/json\r\n"
 . "\r\n"
 . "\r\n["
 . "  {\r\n"
 . "    \"id\": 10,\r\n"
 . "    \"name\": \"testName\",\r\n"
 . "    \"color\": \"testColor\"\r\n"
 . "    \"price\": \"testPrice\"\r\n"
 . "  }\r\n"
 . "]";

$parser = (new HttpParserFactory())->createResponseParser();
$result = $parser->parse($response);