PHP code example of pubconnect / isbn-urn

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

    

pubconnect / isbn-urn example snippets


   use Pubconnect\IsbnUrn\IsbnUrn; 
   
   $urnParser = new IsbnUrn();
   $urnParser->setNamespaceIdentifier('isbn');
   $urnParser->setNamespace('9795363916662');
   $urnParser->setTocItem('3.3.3');
   $urnParser->setOffset(10, 34);
   $urnParser->setTextFragment('de lelijke vos sprong in de bosjes');
   echo $urnParser->getUrn();

   use Pubconnect\IsbnUrn\IsbnUrn; 
   
   $urnString = "urn:isbn:9795363916662";
   $urnParser = new IsbnUrn($urnString);
   $urnParser->setTocItem('4.3.2');
   $urnParser->setOffset(0, 340);
   $urnParser->setTextFragment('de lelijke vos sprong in de bosjes');
   echo $urnParser->getUrn();
   echo PHP_EOL.PHP_EOL;

   use Pubconnect\IsbnUrn\IsbnUrn; 

   $urnStrings[] = "urn:isbn:9795363916662";
   $urnStrings[] = "urn:isbn:9795363916662?segmentnum=5";
   $urnStrings[] = "urn:isbn:9795363916662?tocitem=3.3.3";
   $urnStrings[] = "urn:isbn:9795363916662?tocitem=3.3.3#offset(150)";
   $urnStrings[] = "urn:isbn:9795363916662?tocitem=3.3.3#offset(10,34)";
   $urnStrings[] = "urn:isbn:9795363916662?tocitem=3.3.3#offset(10,34)de+lelijke+vos+sprong+in+de+bosjes";
    
   foreach($urnStrings as $urnString){
     $urnParser = new IsbnUrn($urnString);
     echo "URN: " . $urnParser->getUrn() . PHP_EOL;
     echo "Namespace Identifier: " . $urnParser->getNamespaceIdentifier() . PHP_EOL;
     echo "Namespace: " . $urnParser->getNamespace() . PHP_EOL;
     echo "TOC Item: " . $urnParser->getTocItem() . PHP_EOL;
     echo "Segment Number: " . $urnParser->getSegmentNum() . PHP_EOL;
     echo "Offset: ";
     echo var_export($urnParser->getOffset(), true).PHP_EOL;
     echo "Text Fragment: " . $urnParser->getTextFragment() . PHP_EOL;
     echo PHP_EOL.PHP_EOL;
   }