<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.yaz.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'de',
  ),
  'this' => 
  array (
    0 => 'function.yaz-record.php',
    1 => 'yaz_record',
    2 => 'Returns a record',
  ),
  'up' => 
  array (
    0 => 'ref.yaz.php',
    1 => 'YAZ Funktionen',
  ),
  'prev' => 
  array (
    0 => 'function.yaz-range.php',
    1 => 'yaz_range',
  ),
  'next' => 
  array (
    0 => 'function.yaz-scan.php',
    1 => 'yaz_scan',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/yaz/functions/yaz-record.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.yaz-record" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">yaz_record</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.1, PECL yaz &gt;= 0.9.0)</p><p class="refpurpose"><span class="refname">yaz_record</span> &mdash; <span class="dc-title">Returns a record</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.yaz-record-description">
  <h3 class="title">Beschreibung</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>yaz_record</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> <code class="parameter">$id</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$pos</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$type</code></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="para rdfs-comment">
   The <span class="function"><strong>yaz_record()</strong></span> function inspects a record in the
   current result set at the position specified by parameter
   <code class="parameter">pos</code>. 
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.yaz-record-parameters">
  <h3 class="title">Parameter-Liste</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">id</code></dt>
     <dd>
      <p class="para">
       The connection resource returned by <span class="function"><a href="function.yaz-connect.php" class="function">yaz_connect()</a></span>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">pos</code></dt>
     <dd>
      <p class="para">
       The record position. Records positions in a result set are numbered 1,
       2, ... $hits where $hits is the count returned by <span class="function"><a href="function.yaz-hits.php" class="function">yaz_hits()</a></span>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">type</code></dt>
     <dd>
      <p class="para">
       The <code class="parameter">type</code> specifies the form of the
       returned record.
      </p>
      <blockquote class="note"><p><strong class="note">Hinweis</strong>: 
       <p class="para">
        It is the application which is responsible for actually
        ensuring that the records are returned from the Z39.50/SRW server
        in the proper format. The type given only specifies a conversion
        to take place on the client side (in PHP/YAZ).
       </p>
      </p></blockquote>
      <p class="para">
       Besides conversion of the transfer record to a string/array, PHP/YAZ
       it is also possible to perform a character set conversion of the
       record. Especially for USMARC/MARC21 that is recommended since
       these are typically returned in the character set MARC-8 that is
       not supported by browsers, etc. To specify a conversion, add
       <code class="literal">; charset=</code><span class="replaceable">from</span><code class="literal">,
       </code><span class="replaceable">to</span> where
       <span class="replaceable">from</span> is the original character set 
       of the record and <span class="replaceable">to</span> is the resulting character
       set (as seen by PHP).
      </p>
      <dl>
       
        <dt><code class="literal">string</code></dt>
        <dd>
         <p class="para">
          The record is returned as a string for simple display.
          In this mode, all MARC records are converted to a line-by-line format
          since ISO2709 is hardly readable.
          XML records and SUTRS are returned in their original format.
          GRS-1 are returned in a (ugly) line-by-line format.
         </p>
         <p class="para">
          This format is suitable if records are to be displayed in a quick
          way - for debugging - or because it is not feasible to perform
          proper display.
         </p>
        </dd>
       
       
        <dt><code class="literal">xml</code></dt>
        <dd>
         <p class="para">
          The record is returned as an XML string if possible.
          In this mode, all MARC records are converted to 
          <a href="http://www.loc.gov/standards/marcxml/" class="link external">&raquo;&nbsp;MARCXML</a>.
          XML records and SUTRS are returned in their original format.
          GRS-1 is not supported.
         </p>
         <p class="para">
          This format is similar to <code class="parameter">string</code> except that
          MARC records are converted to MARCXML
         </p>
         <p class="para">
          This format is suitable if records are processed by an XML parser
          or XSLT processor afterwards.
         </p>
        </dd>
       
       
        <dt><code class="literal">raw</code></dt>
        <dd>
         <p class="para">
          The record is returned as a string in its original form.
          This type is suitable for MARC, XML and SUTRS. It does not
          work for GRS-1.
         </p>
         <p class="para">
          MARC records are returned as a ISO2709 string. XML and SUTRS are
          returned as strings.
         </p>
        </dd>
       
       
        <dt><code class="literal">syntax</code></dt>
        <dd>
         <p class="para">
          The syntax of the record is returned as a string, i.e.
          <code class="literal">USmarc</code>, <code class="literal">GRS-1</code>,
          <code class="literal">XML</code>, etc.
         </p>
        </dd>
       
       
        <dt><code class="literal">database</code></dt>
        <dd>
         <p class="para">
          The name of database associated with record at the position
          is returned as a string.
         </p>
        </dd>
       
       
        <dt><code class="literal">array</code></dt>
        <dd>
         <p class="para">
          The record is returned as an array that reflects the GRS-1
          structure. This type is suitable for MARC and GRS-1. XML, SUTRS
          are not supported and if the actual record is XML or SUTRS an
          empty string will be returned.
         </p>
         <p class="para">
          The array returned consists of a list corresponding to
          each leaf/internal node of GRS-1. Each list item consists
          a sub list with first element <em>path</em> and
          <em>data</em> (if data is available).
         </p>
         <p class="para">
          The path which is a string holds a list of each tree component (of
          the structured GRS-1 record) from root to leaf. Each component is
          a tag type, tag value pair of the form
          <code class="literal">(</code><span class="replaceable">type</span><code class="literal">,</code>
          <span class="replaceable">value</span>
         </p>
         <p class="para">
          String tags normally has a corresponding tag type 3.
          MARC can also be returned as an array (they are converted to
          GRS-1 internally).
         </p>
        </dd>
       
      </dl>
     </dd>
    
   </dl>
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.yaz-record-returnvalues">
  <h3 class="title">Rückgabewerte</h3>
  <p class="para">    
   Returns the record at position <code class="parameter">pos</code> or an empty
   string if no record exists at the given position.
  </p>
  <p class="para">
   If no database record exists at the given position an empty string is 
   returned.
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.yaz-record-examples">
  <h3 class="title">Beispiele</h3>
  <div class="example" id="example-1">
   <p><strong>Beispiel #1 Array for GRS-1 record</strong></p>
   <div class="example-contents"><p>
    Consider this GRS-1 record:
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">(4,52)Robert M. Pirsig
(4,70)
      (4,90)
            (2,7)Transworld Publishers, ltd.</pre>
</div>
    </div>
    This record has two nodes at root level. First element at root level is
    (4,52) [tag type 4, tag value 52], and has data <code class="literal">Robert M. 
    Pirsig</code>. Second element at root level (4,70) has a subtree with
    a single element (4,90). (4,90) has yet another sub tree (2,7) with data
    <code class="literal">Transworld Publishers, ltd.</code>.
   </p></div>
   <div class="example-contents"><p>
    If this record is present at position $p, then
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$ar </span><span style="color: #007700">= </span><span style="color: #0000BB">yaz_record</span><span style="color: #007700">(</span><span style="color: #0000BB">$id</span><span style="color: #007700">, </span><span style="color: #0000BB">$p</span><span style="color: #007700">, </span><span style="color: #DD0000">"array"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$ar</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    will output:
    <div class="example-contents screen">
<div class="examplescode"><pre class="examplescode">Array
(
    [0] =&gt; Array
        (
            [0] =&gt; (4,52)
            [1] =&gt; Robert M. Pirsig
        )
    [1] =&gt; Array
        (
            [0] =&gt; (4,70)
        )
    [2] =&gt; Array
        (
            [0] =&gt; (4,70)(4,90)
        )
    [3] =&gt; Array
        (
            [0] =&gt; (4,70)(4,90)(2,7)
            [1] =&gt; Transworld Publishers, ltd.
        )
)</pre>
</div>
    </div>
   </p></div>
  </div>
  <div class="example" id="example-2">
   <p><strong>Beispiel #2 Working with MARCXML</strong></p>
   <div class="example-contents"><p>
    The following PHP snippet returns a MARC21/USMARC record as MARCXML. 
    The original record is returned in marc-8 (unknown to most XML parsers),
    so we convert it to UTF-8 (which all XML parsers must support).
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$rec </span><span style="color: #007700">= </span><span style="color: #0000BB">yaz_record</span><span style="color: #007700">(</span><span style="color: #0000BB">$id</span><span style="color: #007700">, </span><span style="color: #0000BB">$p</span><span style="color: #007700">, </span><span style="color: #DD0000">"xml; charset=marc-8,utf-8"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </p></div>
   <div class="example-contents"><p>
    The record <code class="literal">$rec</code> can be processed with the 
    Sablotron XSLT processor as follows:
   </p></div>
   <div class="example-contents"><p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$xslfile </span><span style="color: #007700">= </span><span style="color: #DD0000">'display.xsl'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$processor </span><span style="color: #007700">= </span><span style="color: #0000BB">xslt_create</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$parms </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'/_xml' </span><span style="color: #007700">=&gt; </span><span style="color: #0000BB">$rec</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$res </span><span style="color: #007700">= </span><span style="color: #0000BB">xslt_process</span><span style="color: #007700">(</span><span style="color: #0000BB">$processor</span><span style="color: #007700">, </span><span style="color: #DD0000">'arg:/_xml'</span><span style="color: #007700">, </span><span style="color: #0000BB">$xslfile</span><span style="color: #007700">, </span><span style="color: #0000BB">NULL</span><span style="color: #007700">, </span><span style="color: #0000BB">$parms</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">xslt_free</span><span style="color: #007700">(</span><span style="color: #0000BB">$processor</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$res </span><span style="color: #007700">= </span><span style="color: #0000BB">preg_replace</span><span style="color: #007700">(</span><span style="color: #DD0000">"'&lt;/?html[^&gt;]*&gt;'"</span><span style="color: #007700">, </span><span style="color: #DD0000">''</span><span style="color: #007700">, </span><span style="color: #0000BB">$res</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$res</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </p></div>
  </div>
 </div>

</div><?php manual_footer($setup); ?>