gopher_parsedir

(PECL net_gopher >= 0.1)

gopher_parsedirTraducir una entrada de directorios con formato gopher a un array asociativo

Descripción

gopher_parsedir ( string $dirent ) : array

gopher_parsedir() convierte una entrada de directorio con formato gopher en un array asociativo.

Aunque gopher devuelve documentos text/plain para peticiones de documentos reales, una petición a un directorio (como /) devolverá series de líneas especialmente codificadas, siendo cada línea una entrada de directorio o línea de información.

Parámetros

dirent

La entrada de directorio.

Valores devueltos

Devuelve un array asociativo cuyos componentes son:

  • type - Una de las constantes GOPHER_XXX.
  • title - El nombre del recurso.
  • path - La ruta del recurso.
  • host - El nombre de dominio del host que posee este documentot (o directorio).
  • port - El puerto al que conectarse en host.

En caso de fallo, la entrada adicional data del array devuelto contendrá la línea procesada.

Ejemplos

Ejemplo #1 Salida hipotéticoa de gopher://gopher.example.com/

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

En el ejemplo anterior, el directorio raíz en gopher.example.com está al tanto de un DOCUMENTO identificado por 0 ubicado en gopher://gopher.example.com:70/allabout.txt. También está al tanto de dos directorios (los cuales tienen sus propios ficheros listados) en gopher://gopher.exmaple.com:70/stories y en gopher://gopher.ejemplo.co.es:70/. Además existe un fichero binario, un enlace a una URL HTTP, y varias líneas informativas.

Al pasar cada línea de la lista de directorios a gopher_parsedir(), se forma un array asociativo que contiene una versión desglosada de la información.

Ejemplo #2 Utilizar gopher_parsedir()

<?php
$directorio 
file("gopher://gopher.example.com");

foreach(
$directorio as $entrada) {
    
print_r(gopher_parsedir($entrada));
}
?>

El resultado del ejemplo sería:

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
)