uTools-Manuals/docs/php/gopher_parsedir.html
2019-04-08 23:22:26 +08:00

217 lines
7.4 KiB
HTML

<!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 class="docs"><div id="layout">
<div id="layout-content"><div id="function.gopher-parsedir" class="refentry">
<div class="refnamediv">
<h1 class="refname">gopher_parsedir</h1>
<p class="verinfo">(PECL net_gopher &gt;= 0.1)</p><p class="refpurpose"><span class="refname">gopher_parsedir</span> &mdash; <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">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>gopher_parsedir</strong></span>
( <span class="methodparam"><span class="type">string</span> <code class="parameter">$dirent</code></span>
) : <span class="type">array</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">参数</h3>
<p class="para">
<dl>
<dt>
<code class="parameter">dirent</code></dt>
<dd>
<p class="para">
The directory entry.
</p>
</dd>
</dl>
</p>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.gopher-parsedir-returnvalues">
<h3 class="title">返回值</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">范例</h3>
<p class="para">
<div class="example" id="example-5363">
<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-5364">
<p><strong>Example #2 Using <span class="function"><strong>gopher_parsedir()</strong></span></strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$directory&nbsp;</span><span style="color: #007700">=&nbsp;</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&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$dirent</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</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">?&gt;</span>
</span>
</pre></div>
</div>
<div class="example-contents"><p>以上例程会输出:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
Array (
[type] =&gt; 0
[title] =&gt; All about my gopher site.
[path] =&gt; /allabout.txt
[host] =&gt; gopher.example.com
[port] =&gt; 70
)
Array (
[type] =&gt; 9
[title] =&gt; A picture of my cat.
[path] =&gt; /pics/cat.png
[host] =&gt; gopher.example.com
[port] =&gt; 70
)
Array (
[type] =&gt; 1
[title] =&gt; A collection of my writings.
[path] =&gt; /stories
[host] =&gt; gopher.example.com
[port] =&gt; 70
)
Array (
[type] =&gt; 254
[title] =&gt; The HTTP version of this site.
[path] =&gt; URL:http://www.example.com
[host] =&gt; gopher.example.com
[port] =&gt; 70
)
Array (
[type] =&gt; 1
[title] =&gt; Mirror of this site in Spain.
[path] =&gt; /
[host] =&gt; gopher.ejemplo.co.es
[port] =&gt; 70
)
Array (
[type] =&gt; 255
[title] =&gt; Welcome to my gopher site.
[path] =&gt;
[host] =&gt; error.host
[port] =&gt; 1
)
Array (
[type] =&gt; 255
[title] =&gt; Please select one of the options above.
[path] =&gt;
[host] =&gt; error.host
[port] =&gt; 1
)
Array (
[type] =&gt; 255
[title] =&gt; Send complaints to /dev/null
[path] =&gt;
[host] =&gt; error.host
[port] =&gt; 1
)
Array (
[type] =&gt; 255
[title] =&gt; Long live gopher!
[path] =&gt;
[host] =&gt; error.host
[port] =&gt; 1
)
</pre></div>
</div>
</div>
</p>
</div>
</div></div></div></body></html>