Pretty print a MARC record retrieved through the PECL yaz extension

  1. <?php
  2. $dir dirname(__FILE__);
  3. require $dir '/../' 'MARC.php';
  4.  
  5. // Define the usable fields for our CCL query
  6. $ccl_fields array(
  7.   "ti" => "1=4",
  8.   "au"  => "1=1",
  9.   "isbn" => "1=7"
  10. );
  11.  
  12. // Declare the array that will hold the parsed results
  13. $ccl_results array();
  14.  
  15. // Connect to the laurentian.ca Z39.50 server
  16. $conn yaz_connect('142.51.8.7:2200/UNICORN');
  17. yaz_ccl_conf($conn$ccl_fields);
  18.  
  19. // Define our query for a most excellent text
  20. $ccl_query "ti='derby' and au='scott'";
  21.  
  22. // Parse the CCL query into yaz's native format
  23. $result yaz_ccl_parse($conn$ccl_query$ccl_results);
  24. if (!$result{
  25.   echo "Error: " $ccl_results['errorstring'];
  26.   exit();
  27. }
  28.  
  29. // Submit the query
  30. $rpn $ccl_results['rpn'];
  31. yaz_search($conn'rpn'$rpn);
  32.  
  33. // Any errors trying to retrieve this record?
  34. $error yaz_error($conn);
  35. if ($error{
  36.   print "Error$error\n";
  37.   exit();
  38. }
  39.  
  40. // Retrieve the first MARC record as raw MARC
  41. $rec yaz_record($conn1"raw");
  42. if (!$rec{
  43.   print "Error: Retrieved no results.\n";
  44.   exit();
  45. }
  46.  
  47. // Parse the retrieved MARC record
  48. $marc_file new MARC($recMARC_SOURCE_STRING)
  49.  
  50. // how many records?
  51. print "Number of records: " $marc_file->numRecords("\n";
  52.  
  53. while ($marc_record $marc_file->next()) {
  54.   print $marc_record;
  55.   print "\n";
  56. }
  57. ?>

Documentation generated on Mon, 14 Aug 2006 18:59:28 -0400 by phpDocumentor 1.3.0RC6