1. Go to this page and download the library: Download beheh/sulphur 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/ */
beheh / sulphur example snippets
// fetch masterserver response
$parser = new BehEh\Sulphur\Parser();
$response = $parser->parse(file_get_contents('example.com:80'));
// count all running games
echo count($response->where('State')->is('Running')).' game(s) are currently running';
// iterate through all games currently in lobby
foreach($response->where('State')->is('Lobby') as $reference) {
echo $reference->Title.' is now open!';
}
// show comment of first game containing "CMC" (case insensitive)
$references = $response->where('Title')->contains('cmc', true);
echo $references[0]->Comment;
// show title of first running league game
$references = $response->where('State')->is('Running')
->where('League')->doesNotExist();
echo $references[0]->Title;
// count games for Clonk Rage or OpenClonk
$references = $response->where('Game')->passes(function($field, $value) { return $value === 'Clonk Rage' || $value === 'OpenClonk'; });
echo count($references).' Clonk Rage and OpenClonk games open';
// print all player names in a reference
foreach($reference->first('PlayerInfos')->all('Client') as $client) {
foreach($client->all('Player') as $player) {
echo $player->Name;
}
}
use BehEh\Sulphur\Parser;
$parser = new Parser();
$response = $parser->parse($data);