PHP code example of kjantzer / ponipar

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

    

kjantzer / ponipar example snippets


use PONIpar\Parser;
use PONIpar\ProductSubitem\ProductIdentifier;
use PONIpar\ProductSubitem\Title;
use PONIpar\ProductSubitem\Contributor;
use PONIpar\ProductSubitem\Extent;
use PONIpar\ProductSubitem\SupplyDetail;

$parse_product = function($product){
	
	$isbn_13 = $product->getIdentifier(ProductIdentifier::TYPE_ISBN13);
	
	// there can be multiple titles
	$titles = $product->getTitles();
	$main_title = '';
	
	// find the  main title
	foreach ($titles as $item) {
		if( $item->getType() == Title::TYPE_DISTINCTIVE_TITLE )
			$main_title = $item->getValue();
	}
	
	// get list of contributor names
	$contributors = $product->getContributors();
	$contributor_names = array_map(function($c){
		return $c->getName();
	}, $contributors);
	
	$bisac = $product->getMainSubjectBISAC();
	
	$description = $product->getMainDescription();
	
	$is_active = $product->isActive();
	
	// get supply info
	$supply_details = $product->getSupplyDetails();
	
	$supply_detail = $supply_details[0];
	
	$supply_detail->getOnSaleDate();
	$supply_detail->getPrices();
}

$parser = new Parser();	
$parser->useFile($file);
$parser->setProductHandler($parse_product);
$parser->parse();