PHP - Fonction pathinfo ()
La fonction pathinfo () peut renvoyer un tableau contenant des informations sur un chemin. Si le paramètre options n'est pas passé, un tableau associatif contenant les éléments est renvoyé: dirname, basename, extension (le cas échéant) et filename.
Syntaxe
mixed pathinfo ( string $path [, int $options = PATHINFO_DIRNAME | PATHINFO_BASENAME | PATHINFO_EXTENSION | PATHINFO_FILENAME ] )
Cette fonction pathinfo () peut renvoyer des informations sur le chemin: soit un tableau associatif, soit une chaîne, selon les options.
Exemple 1
<?php
print_r(pathinfo("/PhpProject/simple.txt"));
?>
Production
Array
(
[dirname] => /PhpProject1
[basename] => simple.txt
[extension] => txt
[filename] => simple
)
Exemple-2
<?php
print_r(pathinfo("/PhpProject/simple.txt", PATHINFO_BASENAME));
?>
Production
simple.txt