PHP code example of scriptotek / oai-pmh-client

1. Go to this page and download the library: Download scriptotek/oai-pmh-client 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/ */

    

scriptotek / oai-pmh-client example snippets



use Scriptotek\OaiPmh\Client as OaiPmhClient;

$url = 'http://oai.bibsys.no/repository';

$client = new OaiPmhClient($url, array(
    'schema' => 'marcxchange',
    'user-agent' => 'MyTool/0.1',
    'max-retries' => 10,
    'sleep-time-on-error' => 30,
));

try {
    $record = $client->record('oai:bibsys.no:biblio:113889372');
} catch (Scriptotek\OaiPmh\ConnectionError $e) {
    echo $e->getMsg();
    die;
} catch (Scriptotek\OaiPmh\BadRequestError $e) {
    echo 'Bad request: ' . $e->getMsg() . "\n";
    die;
}

echo $record->identifier . "\n";
echo $record->datestamp . "\n";
echo $record->data->asXML() . "\n";

foreach ($client->records('') as $record) {
	echo $record->identifier . "\n";
	echo $record->datestamp . "\n";
}

$client->on('request.start', function($verb) {
    print "Starting " . $verb . " request\n";
});
$client->on('request.error', function($err) {
    print "Non-fatal error: " . $err . "\n";
});
$client->on('request.complete', function($verb) {
    print "Completed " . $verb . " request\n";
});