PHP code example of oasys / negotiator

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

    

oasys / negotiator example snippets


 declare(strict_types=1);

use Oasys\Http\Negotiator;

$result = Negotiator::content(
    header: 'application/json, text/html;q=0.8',
    supported: ['text/html', 'application/json']
);

'application/json'

$result = Negotiator::content(
    'text/*;q=0.3, text/plain;q=0.7, text/plain;format=flowed, */*;q=0.5',
    ['text/plain', 'text/plain;format=flowed', 'text/html']
);

'text/plain;format=flowed'

$result = Negotiator::language(
    'de-*-DE, fr;q=0.5',
    ['de-Latn-DE', 'fr-FR']
);

'de-Latn-DE'

$result = Negotiator::language(
    'en, fr;q=0.5',
    ['en-US', 'fr-FR'],
    extendedFiltering: false
);

'en-US'

$result = Negotiator::encoding(
    'gzip, br',
    ['7z']
);

'identity'

$result = Negotiator::encoding(
    'gzip, br',
    ['7z'],
    identity: false
);

null

$result = Negotiator::charset(
    'utf-8, windows-1250;q=0.5, *;q=0.1',
    ['windows-1250', 'utf-8']
);

'utf-8'