A Simple Holdings Lookup Script - in PHP and Perl
Below you will find examples of the Simple Holdings Lookup Script, coded in Perl and PHP. We would be greatly interested to see examples in as many languages as possible - let us know how you get on in your favourite language.
PHP Example - One difference is that it uses the JSON output of the holdings service, whereas the Python example uses RDF.
<?php
require_once('JSON.php'); // from http://pear.php.net/pepr/pepr-proposal-show.php?id=198
$json = new Services_JSON();
$isbn = $_GET{'isbn'};
$url = "http://api.talis.com/1/bib/holdings?api_key={KEY}&output=json&isbn=$isbn";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);
curl_close($ch);
$data = $json->decode($content);
foreach ($data->{'Holdings'}->{$isbn} as $holding) {
echo '<p><a href="http://api.talis.com/1/node/items/' . $holding->{'identifier'} . '/bib?api_key={KEY}&isbn=' . $isbn . '">' . $holding->{'name'} . '</a></p>' ;
}
?>
Perl Example - One difference is that it uses the JSON output of the holdings service, whereas the Python example uses RDF.
#!/usr/bin/perl
use strict;
use LWP::Simple;
use CGI qw/:standard/;
use XML::Simple;
my $isbn = param('isbn');
print header;
my $url = "http://api.talis.com/1/bib/holdings?api_key={KEY}&output=xml&isbn=$isbn";
my $content = get($url);
my $ref = XMLin($content);
while (my ($name, $data) = each(%{$ref->{'holding'} } )) {
my $identity = $ref->{'holding'}->{$name}->{'identity'};
print qq~<p><a href="http://api.talis.com/1/node/items/$identity/bib?api_key={KEY}&isbn=$isbn">$name</a></p>\n~;
}



Recent comments
1 week 4 days ago
2 weeks 12 hours ago
5 weeks 9 hours ago
5 weeks 15 hours ago
9 weeks 4 days ago
16 weeks 2 days ago
16 weeks 3 days ago
17 weeks 4 days ago
19 weeks 3 days ago
22 weeks 13 hours ago