PHP code example of georgeh / php-beerxml

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

    

georgeh / php-beerxml example snippets


$parser = new \BeerXML\Parser();
$result = $parser->parse(file_get_contents('http://www.beerxml.com/recipes.xml'));
foreach ($result as $recipe) {
    /** @var $recipe \BeerXML\Record\Recipe **/
    echo "Found beer recipe " . $recipe->getName() . "\n";
}

$recipe = new \BeerXML\Record\Recipe();
$recipe->setName('My Brew');

$generator = new \BeerXML\Generator();
$generator->addRecord($recipe);
$xml = $generator->render();
echo $xml;

$recipe = new \BeerXML\Record\Recipe();
$recipe->setName('Imperial Session');
$recipe->setOg(1.105);
$recipe->setFg(1.002);
$recipe->setIbu(99);
json
{
    "eorgeh/php-beerxml": "*",
    }
}