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 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.
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 dl("gopher.so");
$directory = file("gopher://gopher.example.com");
foreach($directory as $dirent) { print_r(gopher_parsedir($dirent)); }
/* Affichage espéré ---------------
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 ) */ ?>
|
|
Les valeurs données par type sont associées
avec les constantes suivantes :
Tableau 1. Constantes Gopher
Constante | Définition |
---|
GOPHER_DOCUMENT | Document standart text/plain. |
GOPHER_DIRECTORY | Une ressource contenant un listing de dossier formaté gopher. |
GOPHER_BINHEX | Un fichier binaire encodé BinHex. |
GOPHER_DOSBINARY | Une archive binaire formatée DOS. |
GOPHER_UUENCODED | Un fichier UUEncodé. |
GOPHER_BINARY | Un fichier générique binaire. |
GOPHER_INFO | Une entrée d'information. |
GOPHER_HTTP | Une référence à une ressource HTTP. |
GOPHER_UNKNOWN |
Une entrée non-reconnue, la ligne sera retournée dans le paramètre
data.
|