<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Translate a gopher formatted directory entry into an associative array.</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ref.net-gopher.html">Gopher Functions</a></div> <div class="next" style="text-align: right; float: right;"><a href="book.gupnp.html">Gupnp</a></div> <div class="up"><a href="ref.net-gopher.html">Gopher Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.gopher-parsedir" class="refentry"> <div class="refnamediv"> <h1 class="refname">gopher_parsedir</h1> <p class="verinfo">(PECL net_gopher >= 0.1)</p><p class="refpurpose"><span class="refname">gopher_parsedir</span> — <span class="dc-title">Translate a gopher formatted directory entry into an associative array.</span></p> </div> <div class="refsect1 description" id="refsect1-function.gopher-parsedir-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">array</span> <span class="methodname"><strong>gopher_parsedir</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$dirent</code></span> )</div> <p class="para rdfs-comment"> <span class="function"><strong>gopher_parsedir()</strong></span> parses a gopher formatted directory entry into an associative array. </p> <p class="para"> While gopher returns <em>text/plain</em> documents for actual document requests. A request to a directory (such as /) will return specially encoded series of lines with each line being one directory entry or information line. </p> </div> <div class="refsect1 parameters" id="refsect1-function.gopher-parsedir-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">dirent</code></em></span> <dd> <p class="para"> The directory entry. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.gopher-parsedir-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns an associative array whose components are: <ul class="itemizedlist"> <li class="listitem"> <span class="simpara"> <em>type</em> - One of the <em>GOPHER_XXX</em> constants. </span> </li> <li class="listitem"> <span class="simpara"> <em>title</em> - The name of the resource. </span> </li> <li class="listitem"> <span class="simpara"> <em>path</em> - The path of the resource. </span> </li> <li class="listitem"> <span class="simpara"> <em>host</em> - The domain name of the host that has this document (or directory). </span> </li> <li class="listitem"> <span class="simpara"> <em>port</em> - The port at which to connect on <em>host</em>. </span> </li> </ul> </p> <p class="para"> Upon failure, the additional <em>data</em> entry of the returned array will hold the parsed line. </p> </div> <div class="refsect1 examples" id="refsect1-function.gopher-parsedir-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-4335"> <p><strong>Example #1 Hypothetical output from <em>gopher://gopher.example.com/</em></strong></p> <div class="example-contents screen"> <div class="cdata"><pre> 0All about my gopher site. /allabout.txt gopher.example.com 70 9A picture of my cat. /pics/cat.png gopher.example.com 70 1A collection of my writings. /stories gopher.example.com 70 hThe HTTP version of this site. URL:http://www.example.com gopher.example.com 70 1Mirror of this site in Spain. / gopher.ejemplo.co.es 70 iWelcome to my gopher site. error.host 1 iPlease select one of the options above error.host 1 iSend complaints to /dev/null error.host 1 iLong live gopher! error.host 1 </pre></div> </div> </div> </p> <p class="para"> In the example above, the root directory at gopher.example.com knows about one <em>DOCUMENT</em> identified by <em>0</em> located at <em>gopher://gopher.example.com:70/allabout.txt</em>. It also knows about two other directory (which have their own listing files) at <em>gopher://gopher.exmaple.com:70/stories</em> and at <em>gopher://gopher.ejemplo.co.es:70/</em>. In addition there is a binary file, a link to an HTTP url, and several informative lines. </p> <p class="para"> By passing each line of the directory listing into <span class="function"><strong>gopher_parsedir()</strong></span>, an associative array is formed containing a parsed out version of the data. </p> <p class="para"> <div class="example" id="example-4336"> <p><strong>Example #2 Using <span class="function"><strong>gopher_parsedir()</strong></span></strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$directory </span><span style="color: #007700">= </span><span style="color: #0000BB">file</span><span style="color: #007700">(</span><span style="color: #DD0000">"gopher://gopher.example.com"</span><span style="color: #007700">);<br /><br />foreach(</span><span style="color: #0000BB">$directory </span><span style="color: #007700">as </span><span style="color: #0000BB">$dirent</span><span style="color: #007700">) {<br /> </span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">gopher_parsedir</span><span style="color: #007700">(</span><span style="color: #0000BB">$dirent</span><span style="color: #007700">));<br />}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> <div class="example-contents"><p>The above example will output:</p></div> <div class="example-contents screen"> <div class="cdata"><pre> Array ( [type] => 0 [title] => All about my gopher site. [path] => /allabout.txt [host] => gopher.example.com [port] => 70 ) Array ( [type] => 9 [title] => A picture of my cat. [path] => /pics/cat.png [host] => gopher.example.com [port] => 70 ) Array ( [type] => 1 [title] => A collection of my writings. [path] => /stories [host] => gopher.example.com [port] => 70 ) Array ( [type] => 254 [title] => The HTTP version of this site. [path] => URL:http://www.example.com [host] => gopher.example.com [port] => 70 ) Array ( [type] => 1 [title] => Mirror of this site in Spain. [path] => / [host] => gopher.ejemplo.co.es [port] => 70 ) Array ( [type] => 255 [title] => Welcome to my gopher site. [path] => [host] => error.host [port] => 1 ) Array ( [type] => 255 [title] => Please select one of the options above. [path] => [host] => error.host [port] => 1 ) Array ( [type] => 255 [title] => Send complaints to /dev/null [path] => [host] => error.host [port] => 1 ) Array ( [type] => 255 [title] => Long live gopher! [path] => [host] => error.host [port] => 1 ) </pre></div> </div> </div> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ref.net-gopher.html">Gopher Functions</a></div> <div class="next" style="text-align: right; float: right;"><a href="book.gupnp.html">Gupnp</a></div> <div class="up"><a href="ref.net-gopher.html">Gopher Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>