gopher_parsedir
(PECL)
gopher_parsedir -- Transpose une entrée d'un dossier formaté gopher dans un tableau associatif
Description
array
gopher_parsedir ( string dirent )
gopher_parsedir() transpose une entrée d'un dossier formaté gopher
dans un tableau associatif.
Gopher retourne des documents text/plain
pour les documents demandés. Une requête vers un dossier (comme /)
retournera des séries de lignes encodées où chaque ligne est une entrée
du dossier ou une ligne d'informations.
Liste de paramètres
dirent
L'entrée du dossier.
Valeurs de retour
Retourne un tableau associatif dont les composants sont :
type
- Une constante
GOPHER_XXX.
title
- Le nom de la ressource.
path
- Le chemin vers la ressource.
host
- Le nom du domaine de l'hôte qui possède
ce document (ou dossier).
port
- Le port de connexion sur l'hôte
host
.
En cas d'échec, l'entrée additionnelle data
du
tableau retournée contiendra la ligne analysée.
Exemples
Exemple 1. Affichage hypothétique depuis 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 |
|
Dans l'exemple précédent, le dossier racine de gopher.example.com reconnaît un
DOCUMENT identifié par 0 et se trouvant à l'adresse
gopher://gopher.example.com:70/allabout.txt.
Il reconnaît également deux autres dossiers (qui ont leur propre liste de fichiers) à l'adresse
gopher://gopher.exmaple.com:70/stories et à l'adresse
gopher://gopher.ejemplo.co.es:70/.
Il y a également un fichier binaire, un lien vers une url HTTP et plusieurs
lignes d'informations.
En passant chaque ligne du listing de ce dossier à la fonction
gopher_parsedir(), un tableau associatif est formé
contenant une version analysée des données.
Exemple 2. Exemple avec gopher_parsedir()
<?php
$directory = file("gopher://gopher.example.com");
foreach($directory as $dirent) { print_r(gopher_parsedir($dirent)); } ?>
|
L'exemple ci-dessus va afficher : 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
) |
|