PHP code example of serkin / ymlparser
1. Go to this page and download the library: Download serkin/ymlparser 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/ */
serkin / ymlparser example snippets
$filename = '/path/to/file/file.xml';
// XMLReader driver - for medium and large xml files
// SimpleXML driver - for small xml files
$parser = new \YMLParser\YMLParser(new \YMLParser\Driver\XMLReader);
$parser->open($filename); // throws \Exception if $filename doesn't exist or empty
foreach($parser->getOffers() as $offer): // YMLParser::getOffers() returns \Generator
echo $offer['url'];
endforeach;
$filename = '/path/to/file/file.xml';
$parser = new \YMLParser\YMLParser(new \YMLParser\Driver\SimpleXML);
$parser->open($filename);
// We want offers only with not empty url subelements
$filter = function($element) { return !empty($element['url']); };
$offers = iterator_to_array($parser->getOffers($filter));
// Let's get all params from first offer if they are exist
foreach($offers[0]['params'] as $param):
echo $param['name'] . ' - ' . $param['value'];
endforeach;