<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >yaz_record</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="Manual do PHP" HREF="index.html"><LINK REL="UP" TITLE="YAZ Functions" HREF="ref.yaz.html"><LINK REL="PREVIOUS" TITLE="yaz_range" HREF="function.yaz-range.html"><LINK REL="NEXT" TITLE="yaz_scan_result" HREF="function.yaz-scan-result.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Manual do PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.yaz-range.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.yaz-scan-result.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.yaz-record" ></A >yaz_record</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN241420" ></A ><P > (PHP 4 >= 4.0.1, PECL)</P >yaz_record -- Returns a record</DIV ><DIV CLASS="refsect1" ><A NAME="AEN241423" ></A ><H2 >Descrição</H2 >string <B CLASS="methodname" >yaz_record</B > ( resource id, int pos, string type )<BR ></BR ><P > The <B CLASS="function" >yaz_record()</B > 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" ><A NAME="AEN241440" ></A ><H2 >Parâmetros</H2 ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >id</CODE ></DT ><DD ><P > The connection resource returned by <A HREF="function.yaz-connect.html" ><B CLASS="function" >yaz_connect()</B ></A >. </P ></DD ><DT ><CODE CLASS="parameter" >pos</CODE ></DT ><DD ><P > The record position. Records positions in a result set are numbered 1, 2, ... $hits where $hits is the count returned by <A HREF="function.yaz-hits.html" ><B CLASS="function" >yaz_hits()</B ></A >. </P ></DD ><DT ><CODE CLASS="parameter" >type</CODE ></DT ><DD ><P > The <CODE CLASS="parameter" >type</CODE > specifies the form of the returned record. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >Nota: </B > 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 ></BLOCKQUOTE ></DIV ><P > 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 <TT CLASS="literal" >; charset=</TT ><TT CLASS="replaceable" ><I >from</I ></TT ><TT CLASS="literal" >, </TT ><TT CLASS="replaceable" ><I >to</I ></TT > where <TT CLASS="replaceable" ><I >from</I ></TT > is the original character set of the record and <TT CLASS="replaceable" ><I >to</I ></TT > is the resulting character set (as seen by PHP). </P ><P ></P ><DIV CLASS="variablelist" ><DL ><DT ><TT CLASS="literal" >string</TT ></DT ><DD ><P > 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 > 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 ><TT CLASS="literal" >xml</TT ></DT ><DD ><P > 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/" TARGET="_top" >MARCXML</A >. XML records and SUTRS are returned in their original format. GRS-1 is not supported. </P ><P > This format is similar to <CODE CLASS="parameter" >string</CODE > except that MARC records are converted to MARCXML </P ><P > This format is suitable if records are processed by an XML parser or XSLT processor afterwards. </P ></DD ><DT ><TT CLASS="literal" >raw</TT ></DT ><DD ><P > 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 > MARC records are returned as a ISO2709 string. XML and SUTRS are returned as strings. </P ></DD ><DT ><TT CLASS="literal" >syntax</TT ></DT ><DD ><P > The syntax of the record is returned as a string, i.e. <TT CLASS="literal" >USmarc</TT >, <TT CLASS="literal" >GRS-1</TT >, <TT CLASS="literal" >XML</TT >, etc. </P ></DD ><DT ><TT CLASS="literal" >database</TT ></DT ><DD ><P > The name of database associated with record at the position is returned as a string. </P ></DD ><DT ><TT CLASS="literal" >array</TT ></DT ><DD ><P > 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 > 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 <SPAN CLASS="emphasis" ><I CLASS="emphasis" >path</I ></SPAN > and <SPAN CLASS="emphasis" ><I CLASS="emphasis" >data</I ></SPAN > (if data is available). </P ><P > 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 <TT CLASS="literal" >(</TT ><TT CLASS="replaceable" ><I >type</I ></TT ><TT CLASS="literal" >,</TT > <TT CLASS="replaceable" ><I >value</I ></TT > </P ><P > 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 ></DIV ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN241520" ></A ><H2 >Valores de retornado</H2 ><P > Returns the record at position <CODE CLASS="parameter" >pos</CODE > or an empty string if no record exists at the given position. </P ><P > If no database record exists at the given position an empty string is returned. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN241525" ></A ><H2 >Exemplos</H2 ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN241527" ></A ><P ><B >Exemplo 1. Array for GRS-1 record</B ></P ><P > Consider this GRS-1 record: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >(4,52)Robert M. Pirsig (4,70) (4,90) (2,7)Transworld Publishers, ltd.</PRE ></TD ></TR ></TABLE > 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 <TT CLASS="literal" >Robert M. Pirsig</TT >. 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 <TT CLASS="literal" >Transworld Publishers, ltd.</TT >. </P ><P > If this record is present at position $p, then <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /><br />$ar </font><font color="#007700">= </font><font color="#0000BB">yaz_record</font><font color="#007700">(</font><font color="#0000BB">$id</font><font color="#007700">, </font><font color="#0000BB">$p</font><font color="#007700">, </font><font color="#DD0000">"array"</font><font color="#007700">);<br /></font><font color="#0000BB">print_r</font><font color="#007700">(</font><font color="#0000BB">$ar</font><font color="#007700">);<br /><br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE > will output: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >Array ( [0] => Array ( [0] => (4,52) [1] => Robert M. Pirsig ) [1] => Array ( [0] => (4,70) ) [2] => Array ( [0] => (4,70)(4,90) ) [3] => Array ( [0] => (4,70)(4,90)(2,7) [1] => Transworld Publishers, ltd. ) )</PRE ></TD ></TR ></TABLE > </P ></DIV ></TD ></TR ></TABLE ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN241536" ></A ><P ><B >Exemplo 2. Working with MARCXML</B ></P ><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). <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$rec </font><font color="#007700">= </font><font color="#0000BB">yaz_record</font><font color="#007700">(</font><font color="#0000BB">$id</font><font color="#007700">, </font><font color="#0000BB">$p</font><font color="#007700">, </font><font color="#DD0000">"xml; charset=marc-8,utf-8"</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE > </P ><P > The record <TT CLASS="literal" >$rec</TT > can be processed with the <A HREF="ref.xslt.html" >Sablotron XSLT</A > processor as follows: </P ><P > <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /><br />$xslfile </font><font color="#007700">= </font><font color="#DD0000">'display.xsl'</font><font color="#007700">;<br /></font><font color="#0000BB">$processor </font><font color="#007700">= </font><font color="#0000BB">xslt_create</font><font color="#007700">();<br /></font><font color="#0000BB">$parms </font><font color="#007700">= array(</font><font color="#DD0000">'/_xml' </font><font color="#007700">=> </font><font color="#0000BB">$rec</font><font color="#007700">);<br /></font><font color="#0000BB">$res </font><font color="#007700">= </font><font color="#0000BB">xslt_process</font><font color="#007700">(</font><font color="#0000BB">$processor</font><font color="#007700">, </font><font color="#DD0000">'arg:/_xml'</font><font color="#007700">, </font><font color="#0000BB">$xslfile</font><font color="#007700">, </font><font color="#0000BB">NULL</font><font color="#007700">, </font><font color="#0000BB">$parms</font><font color="#007700">);<br /></font><font color="#0000BB">xslt_free</font><font color="#007700">(</font><font color="#0000BB">$processor</font><font color="#007700">);<br /></font><font color="#0000BB">$res </font><font color="#007700">= </font><font color="#0000BB">preg_replace</font><font color="#007700">(</font><font color="#DD0000">"'</?html[^>]*>'"</font><font color="#007700">, </font><font color="#DD0000">''</font><font color="#007700">, </font><font color="#0000BB">$res</font><font color="#007700">);<br />echo </font><font color="#0000BB">$res</font><font color="#007700">;<br /><br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE > </P ><P > For PHP 5 the <A HREF="ref.xsl.html" >XSL</A > extension must be used instead of Sablotron XSLT. </P ></DIV ></TD ></TR ></TABLE ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.yaz-range.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Principal</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.yaz-scan-result.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >yaz_range</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.yaz.html" ACCESSKEY="U" >Acima</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >yaz_scan_result</TD ></TR ></TABLE ></DIV ></BODY ></HTML >