On Thu 22 Mar 2007, Carlos Escuriola wrote:
> Hello, I'm making a final degree project in my
University and I "playing"
> with YAZ/PHP. I want to retrieve all the information of
a local
> Z39.50server, store that I consider most important
(autor, title,
> ISBN, subjects)
> and then show it in my own way. The problem is that I
don't know if is
> possible to retrieve all the information of a Z39.50
without making a lot
> of individual searching. Exists any php script to get
all this information
> in a only (or few) step?
I'm using your post as a hook to ask a somewhat similar
question.
But first, what do you mean by "all the information of
a Z39.50"?
Do you mean, all the records on the server?
Surely that would be excessive?
If you just mean the whole of one entry,
it seems to me that that is what you - or at any rate - I
get.
I am trying to develop a script more or less along your
lines.
Basically, what I would like to do is:
1. Retrieve a record in XML format from the ISBN number,
and append it to a file. (I've managed to do this.)
2. Analyse the XML entry, and just show:
title, authors, publisher and date of publication as and
HTML table.
I guess this last part is fairly standard,
and in fact I saw a script which more or less did what I
wanted,
but unfortunately I have lost the URL.
Here anyway is my current script.
I am not a PHP expert, and any suggestions or advice
will be very gratefully received.
------------------------------------------------------------
----------------
<html>
<body>
<form method="POST" action="<?php echo
$_SERVER['PHP_SELF']; ?>">
ISBN number: <input type="text"
name="ISBN" />
<input type="submit" />
</form>
<?php
$server = "z3950.loc.gov:7090/voyager";
//$server = "library.tcd.ie:210/advance";
function isbncheck($entry) {
if (ereg('[^-0-9X]$', $entry)) {
echo
"ISBN number can only contain digits 0-9, letter X
and hyphens (-'s)";
return 0;
}
$isbn=ereg_replace("-","",$entry);
if (strlen($isbn)!=10) {
echo "Number must be of length 10
(excluding -'s)";
return 0;
}
$j=0;
for ($i = 0; $i < 9; $i++)
$j += $isbn[$i] * (10 - $i);
if ($isbn[9] == "X")
$j += 10;
else
$j += $isbn[9];
if ($j % 11 == 0)
return $isbn;
else {
echo "ISBN has wrong checksum (last
character)";
return 0;
}
}
$entry=$_POST["ISBN"];
$isbn=isbncheck($entry);
echo "ISBN $isbn: ";
$id = yaz_connect($server);
$query = " attr 1=7 $isbn";
yaz_syntax($id, "xml");
yaz_range($id, 1, 10);
yaz_search($id, "rpn", $query);
yaz_wait();
$error = yaz_error($id);
if (!empty($error))
echo "Error: $error";
else {
$hits = yaz_hits($id);
if ($hits==0)
echo "No match";
elseif ($hits == 1)
echo "1 match";
else
echo "$hits matches";
}
echo '<dl>';
for ($p = 1; $p <= 10; $p++) {
$rec = yaz_record($id, $p, "string");
if (empty($rec)) continue;
echo
"<dt><b>$p</b></dt><dd>&q
uot;;
echo nl2br($rec);
echo "</dd>";
}
echo '</dl>';
$filename = 'test.txt';
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
$rec = yaz_record($id, 1, "string");
if (fwrite($handle, $rec) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
fclose($handle);
} else {
echo "The file $filename is not writable";
}
?><br />
</body>
</html>
------------------------------------------------------------
----------------
--
Timothy Murphy
e-mail (<80k only): tim /at/ birdsnest.maths.tcd.ie
tel: +353-86-2336090, +353-1-2842366
s-mail: School of Mathematics, Trinity College, Dublin 2,
Ireland
_______________________________________________
Yazlist mailing list
Yazlist lists.indexdata.dk
http://lists.indexdata.dk/cgi-bin/mailman/listinfo/yaz
list
|